Rendering multiple views

Hi,
How can i render multiple views in rails?
For example i have two .rhtml files:

header.rhtml -> a chunk of html codes to be rendered on top of the
page
sidebar.rhtml -> also a chunk of html, to be rendered in the right
side of the page

How can i call this .rhtml files from the controller and assign it to
my layout? thanks!

On Sat, Jul 5, 2008 at 1:04 PM, [email protected]
[email protected] wrote:

How can i render multiple views in rails?
For example i have two .rhtml files:
header.rhtml → a chunk of html codes to be rendered on top of the
page
sidebar.rhtml → also a chunk of html, to be rendered in the right
side of the page
How can i call this .rhtml files from the controller and assign it to
my layout? thanks!

You do this with “content_for” calls.

In your layout file, have multiple yield commands… like this;

<%= yield :sidebar -%>
<%= yield :content -%>
<%= yield :footer -%>

Then in the partial:

<% content_for :sidebar do -%>
<%= render :partial => ‘sidebar’ -%>
<% end -%>
<% content_for :footer do -%>
<%= render :partial => ‘footer’ -%>
<% end -%>

This text ends up in the #Content div in the layout as it is the default

Hope that helps

Mikel

Rails, RSpec and Life blog…

oops I stuffed up on the example

On Sat, Jul 5, 2008 at 4:45 PM, Mikel L. [email protected]
wrote:

Should be:

<%= yield :sidebar -%>
<%= yield -%>
<%= yield :footer -%>

Sorry.

Mikel

Rails, RSpec and Life blog…

So I can call the render method in the Views? Can i also have multiple
render method calls in the controller methods?
Thanks…

On Sat, Jul 5, 2008 at 7:34 PM, [email protected]
[email protected] wrote:

So I can call the render method in the Views?

Yes.

Can i also have multiple
render method calls in the controller methods?

Never tried that, but that would not be good. Keep your view logic in
the views, not in the controller.

Rails, RSpec and Life blog…

On Jul 5, 10:34 am, “[email protected][email protected]
wrote:

So I can call the render method in the Views? Can i also have multiple
render method calls in the controller methods?
Thanks…

Try it and find out. It will be a hell of a lot quicker than waiting
for an answer from a mailing list. (Hint, check out the
DoubleRenderError exception ).

Fred