Forum: Ruby on Rails How to render more than one partial?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zhao Y. (Guest)
on 2008-12-31 08:24
I want to render more than one partial in this code:

render :partial => 'project_version'

how can I do this?
Ryan B. (Guest)
on 2008-12-31 10:22
(Received via mailing list)
Render the other partial inside that partial.
-----
Ryan B.
Freelancer
http://frozenplague.net
Zhao Y. (Guest)
on 2008-12-31 13:07
Ryan B. wrote:
> Render the other partial inside that partial.
> -----
> Ryan B.
> 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?
Ramu (Guest)
on 2008-12-31 17:07
(Received via mailing list)
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' %>



On Wed, Dec 31, 2008 at 4:37 PM, Zhao Yi
<removed_email_address@domain.invalid>wrote:

>
>    </tr>
>
> You want me to render "view_name" inside "project_version", how can I do
> this in _project_version.html.erb?
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
Ramu
Zhao Y. (Guest)
on 2009-01-01 03:19
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.
Ramu (Guest)
on 2009-01-01 11:29
(Received via mailing list)
write <tr> in partial files

Your main file in my example a.rhtml will look like
<%= render :partial=>'b'%>
<%= render :partial=>'c' %>



On Thu, Jan 1, 2009 at 6:49 AM, Zhao Yi
<removed_email_address@domain.invalid>wrote:

> >
> --
>  Posted via http://www.ruby-forum.com/.
>
> >
>


--
Ramu
pepe (Guest)
on 2009-01-01 15:52
(Received via mailing list)
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?

On Dec 31 2008, 6:07 am, Zhao Yi <removed_email_address@domain.invalid>
Zhao Y. (Guest)
on 2009-01-02 10:39
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?
>
> On Dec 31 2008, 6:07�am, Zhao Yi <removed_email_address@domain.invalid>

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.
pepe (Guest)
on 2009-01-03 17:55
(Received via mailing list)
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
Zhao Y. (Guest)
on 2009-01-04 14:52
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.
Scott N. (Guest)
on 2009-01-04 18:16
(Received via mailing list)
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>
pepe (Guest)
on 2009-01-04 21:55
(Received via mailing list)
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
Zhao Y. (Guest)
on 2009-01-05 02:51
Hi,

Thanks very much for your explaining. You are right. I can make it more
simple.

thanks again.

Zhao Yi
pepe (Guest)
on 2009-01-05 18:03
(Received via mailing list)
Glad I could help. Good luck.

Pepe
This topic is locked and can not be replied to.