How to render more than one partial?

I want to render more than one partial in this code:

render :partial => 'project_version'

how can I do this?

Render the other partial inside that partial.

Ryan Bigg wrote:

Render the other partial inside that partial.
-----
Ryan Bigg
Freelancer
http://frozenplague.net

Sorry, I am confused.

This piece of code is my case:

<tr>
      <td>Version:</td>
      <td id="project_version">
        <%= render :partial=>'project_version'%>
      </td>
    </tr>

    <tr>
      <td>View Name:</td>
      <td id="view_name"><%= render(:partial=>'view_name') %></td>
    </tr>

You want me to render "view_name" inside "project_version", how can I do
this in _project_version.html.erb?

Your code will does this job.

Is your problem some thing like:
you have a.rhtml file
int that you have to show _b.rhtml file contents as well as _c.rhtml contents?

Then write your code like this:

== This is a.rhtml file

<%= render :partial=>‘b’%>

<%= render :partial=>‘c’ %>

Ramu wrote:

Your code will does this job.

Is your problem some thing like:
you have a.rhtml file
int that you have to show _b.rhtml file contents as well as _c.rhtml
contents?

Then write your code like this:

== This is a.rhtml file

  <%= render :partial=>'b'%>

  <%= render :partial=>'c' %>
--
Ramu

But how can I handle the <tr> element? the two partial should be in
different <tr> element.

write

in partial files

Your main file in my example a.rhtml will look like

<%= render :partial=>‘b’%>
<%= render :partial=>‘c’ %>

Hello.

I don't see anything wrong with this code. Do you want to do something
different than this? I guess I am not understanding the problem?

pepe wrote:

Hello.

I don't see anything wrong with this code. Do you want to do something
different than this? I guess I am not understanding the problem?

I mean in this way, I have to split the <tr> tag. Take this partial for
an example:

    ...
  </tr>
  <tr>
    ....

The other part of the <tr> is in the view page. Have you tried this? I
got a display problem.

I am sorry Zhao but I still don't understand the problem. A concrete
example would probably help. However, lets try something here to see
if it helps.

You should be able to split your page and put into partials whatever
parts of the full page you want/need. As long as the final complete
page is valid HTML it should work fine. An example:

Supposing you need to display something like this:
<tr>
  <td>Text A<td>
  <td>Text B<td>
</tr>
<tr>
  <td>Text C<td>
  <td>Text D<td>
</tr>

You could leave in your main page the following:
<tr>
  <td>Text A<td>
  <%= :render :partial => 'your_partial' %>
  <td>Text D<td>
</tr>

And if your partial delivers:
  <td>Text B<td>
</tr>
<tr>
  <td>Text C<td>

Your final product should be what you originally intended.

Another sample based on the original listed above. You cold leave in
your page:
<tr>
  <%= :render :partial => 'your_A_and_B_partial' %>
</tr>
<tr>
  <%= :render :partial => 'your_C_and_D_partial' %>
</tr>

If 'your_A_and_B_partial' delivers:
  <td>Text A<td>
  <td>Text B<td>

And 'your_C_and_D_partial' delivers:
  <td>Text C<td>
  <td>Text D<td>

You would get the expected results.

I hope it helps. If it still does not help send a concrete example of
what the final page should look like and what parts of the page you
want to make partials and I'll try to help.

Pepe

pepe wrote:

Another sample based on the original listed above. You cold leave in
your page:
<tr>
  <%= :render :partial => 'your_A_and_B_partial' %>
</tr>
<tr>
  <%= :render :partial => 'your_C_and_D_partial' %>
</tr>

If 'your_A_and_B_partial' delivers:
  <td>Text A<td>
  <td>Text B<td>

And 'your_C_and_D_partial' delivers:
  <td>Text C<td>
  <td>Text D<td>

You would get the expected results.
Pepe

Let's take a look at your example above. How can I render both
'your_A_and_B_partial' and 'your_C_and_D_partial'? As you said, I can
render 'your_C_and_D_partial' in the partial 'your_A_and_B_partial'. But
how can I do this?

thanks.

are you trying to this???

# your main file
<tr>
  <%= :render :partial => 'A_B_C_D_partial' %>
</tr>

# A_B_C_D_partial contains
  <%= :render :partial => 'A_B_partial' %>
</tr>
<tr>
  <%= :render :partial => 'C_D_partial' %>

# A_B_partial contains and outputs
  <td>Text A<td>
  <td>Text B<td>

# C_D_partial contains and outputs
  <td>Text C<td>
  <td>Text D<td>

# 'A_B_C_D_partial' outputs:
  <td>Text A<td>
  <td>Text B<td>
</tr>
<tr>
  <td>Text C<td>
  <td>Text D<td>

# your final combined output
<tr>
  <td>Text A<td>
  <td>Text B<td>
</tr>
<tr>
  <td>Text C<td>
  <td>Text D<td>
</tr>

Hi there.

If I understand well what you need I think you are trying to make
things more complicated than they should be. Forget about your table
rows for a moment and lets look at just text. Let's say that I have to
output the following lines:

This is my line number 1
This is my line number 2
This is my line number 3
This is my line number 4
This is my line number 5

To make things easy I'll say that my program has the following code,
with no loops:

puts 'This is my line number 1'
puts 'This is my line number 2'
puts 'This is my line number 3'
puts 'This is my line number 4'
puts 'This is my line number 5'

Now, if I say that what my program always have to output are lines 1
and 5 and whatever comes in the middle can vary I encapsulate the
inner lines in a method call:

puts 'This is my line number 1'
print_rest_of_lines
puts 'This is my line number 5'

def print_rest_of_lines
  puts 'This is my line number 2'
  puts 'This is my line number 3'
  puts 'This is my line number 4'
end

The result is what I expect, the 5 lines printed in the sequence I
wrote at the beginning.

If you treat your partial the same way as you wold treat the method
call you will produce the same effect.

What I was trying to explain in the previous posting is not that you
render 'your_C_and_D_partial from 'your_A_and_B_partial'. What I was
trying to say is that you can just divide your table rows in as many
(or as little) partials as you need. Just remember that a partial
behaves the same as a method call and you'll understand what you'll
get out of it.

Pepe

Glad I could help. Good luck.

Pepe