# Rendering multiple views

**URL:** <https://www.ruby-forum.com/t/rendering-multiple-views/142244>\
**Category:** Rails\
**Created:** [July 5, 2008, 5:05am UTC](https://www.ruby-forum.com/t/rendering-multiple-views/142244 "2008-07-05T05:05:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 5, 2008, 5:05am UTC](https://www.ruby-forum.com/t/rendering-multiple-views/142244/1 "2008-07-05T05:05:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 5, 2008, 8:46am UTC](https://www.ruby-forum.com/t/rendering-multiple-views/142244/2 "2008-07-05T08:46:25Z")

</div>

On Sat, Jul 5, 2008 at 1:04 PM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

–

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar

Rails, RSpec and Life blog…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 5, 2008, 8:47am UTC](https://www.ruby-forum.com/t/rendering-multiple-views/142244/3 "2008-07-05T08:47:35Z")

</div>

oops I stuffed up on the example

On Sat, Jul 5, 2008 at 4:45 PM, Mikel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 

Should be:

 \<%= yield :sidebar -%\> 

 \<%= yield -%\> 

 \<%= yield :footer -%\> 

Sorry.

Mikel

–

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar

Rails, RSpec and Life blog…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 5, 2008, 11:34am UTC](https://www.ruby-forum.com/t/rendering-multiple-views/142244/4 "2008-07-05T11:34:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 5, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/rendering-multiple-views/142244/5 "2008-07-05T14:52:15Z")

</div>

On Sat, Jul 5, 2008 at 7:34 PM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

–

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar

Rails, RSpec and Life blog…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 5, 2008, 3:50pm UTC](https://www.ruby-forum.com/t/rendering-multiple-views/142244/6 "2008-07-05T15:50:45Z")

</div>

On Jul 5, 10:34 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
