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 B.
Freelancer

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:

Version: <%= render :partial=>'project_version'%>
<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’ %>

On Wed, Dec 31, 2008 at 4:37 PM, Zhao Yi
[email protected]wrote:

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

write 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
[email protected]wrote:


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


Ramu

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 [email protected]

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

element? the two partial should be in
different element.

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 [email protected]

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

...
....

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

pepe wrote:

Another sample based on the original listed above. You cold leave in
your page:

<%= :render :partial => 'your_A_and_B_partial' %> <%= :render :partial => 'your_C_and_D_partial' %>

If ‘your_A_and_B_partial’ delivers:

Text A Text B

And ‘your_C_and_D_partial’ delivers:

Text C Text D

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.

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:

Text A Text B Text C Text D

You could leave in your main page the following:

Text A <%= :render :partial => 'your_partial' %> Text D

And if your partial delivers:

Text B Text C

Your final product should be what you originally intended.

Another sample based on the original listed above. You cold leave in
your page:

<%= :render :partial => 'your_A_and_B_partial' %> <%= :render :partial => 'your_C_and_D_partial' %>

If ‘your_A_and_B_partial’ delivers:

Text A Text B

And ‘your_C_and_D_partial’ delivers:

Text C Text D

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

are you trying to this???

your main file

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

A_B_C_D_partial contains

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

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

A_B_partial contains and outputs

Text A Text B

C_D_partial contains and outputs

Text C Text D

‘A_B_C_D_partial’ outputs:

Text A Text B Text C Text D

your final combined output

Text A Text B Text C Text D

Hi,

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

thanks again.

Zhao Yi

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