# How to call mutiple actions in one layout

**URL:** <https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736>\
**Category:** Rails\
**Created:** [October 30, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736 "2007-10-30T15:15:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [October 30, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736/1 "2007-10-30T15:15:27Z")

</div>

hi

for a few days now I am searching for a solution for this problem:

I would like to render multiple actions in a layout.

For example:  
I have in the welcome layout two divs:  
1 menubar and a main.

the menu bar has his one controller with the action: list  
and the main has a controller (for example: article\_controller.rb) with  
the action: list.

both of the actions I want it to be used when the page is loading but i  
dont now how.  
I now i can use \<%= yield :layout %\> for the main. But then I dont  
render the menu.

can I render the action: list in menu when the page is loaded ?  
then call the action: list in article…

I hope you understand my problem (it was hard to explain 😛 )

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [October 30, 2007, 7:13pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736/2 "2007-10-30T19:13:57Z")

</div>

Heldop S. wrote:

> hi
> 
> for a few days now I am searching for a solution for this problem:
> 
> I would like to render multiple actions in a layout.
> 
> For example:  
> I have in the welcome layout two divs:  
> 1 menubar and a main.
> 
> the menu bar has his one controller with the action: list  
> and the main has a controller (for example: article\_controller.rb) with  
> the action: list.

use iframes

walla. you can style the iframes so they have no border, etc; basically,  
this is (definitely) the way to go.

enjoy  
shai

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [October 30, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736/3 "2007-10-30T19:32:57Z")

</div>

Shai R. wrote:

> Heldop S. wrote:
> 
> > hi
> > 
> > for a few days now I am searching for a solution for this problem:
> > 
> > I would like to render multiple actions in a layout.
> > 
> > For example:  
> > I have in the welcome layout two divs:  
> > 1 menubar and a main.
> > 
> > the menu bar has his one controller with the action: list  
> > and the main has a controller (for example: article\_controller.rb) with  
> > the action: list.
> 
> use iframes
> 
> walla. you can style the iframes so they have no border, etc; basically,  
> this is (definitely) the way to go.
> 
> enjoy  
> shai

THANXS !!

ok well meanwhile I did some thinking and came up with this solution:

create a helper method (for example article\_helper.rb and create an  
action (for example “list\_article”).  
in application.rb you put helper :article

ok if you now call \<%= list\_article %\> you call the action in  
article\_helper.

which solution would be best?  
and why ?

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [October 30, 2007, 8:44pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736/4 "2007-10-30T20:44:03Z")

</div>

Frederick C. wrote:

> > which solution would be best?  
> > and why ?
> 
> Sorry for my previous truncated reply!  
> That won’t work well because you can only call render (except  
> partials) once per action.
> 
> The better way to go with these things is a combination of helpers and  
> partials, eg have a render\_menu\_bar helper.
> 
> Fred

hehe…yes I tryed it but didn’t work…

thanxs though, for the reply

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [October 30, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736/5 "2007-10-30T20:53:30Z")

</div>

I suspect what you really want is nested layouts:

[http://agilewebdevelopment.com/plugins/nested\_layouts](http://agilewebdevelopment.com/plugins/nested_layouts)

good luck!  
Tim

Heldop S. wrote:

> hi
> 
> for a few days now I am searching for a solution for this problem:
> 
> I would like to render multiple actions in a layout.
> 
> For example:  
> I have in the welcome layout two divs:  
> 1 menubar and a main.
> 
> the menu bar has his one controller with the action: list  
> and the main has a controller (for example: article\_controller.rb) with  
> the action: list.
> 
> both of the actions I want it to be used when the page is loading but i  
> dont now how.  
> I now i can use \<%= yield :layout %\> for the main. But then I dont  
> render the menu.
> 
> can I render the action: list in menu when the page is loaded ?  
> then call the action: list in article…
> 
> I hope you understand my problem (it was hard to explain 😛 )

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [October 30, 2007, 8:31pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736/6 "2007-10-30T20:31:51Z")

</div>

> which solution would be best?  
> and why ?

Sorry for my previous truncated reply!  
That won’t work well because you can only call render (except  
partials) once per action.

The better way to go with these things is a combination of helpers and  
partials, eg have a render\_menu\_bar helper.

Fred

---

<div class="post-metadata">

**Author:** ![heldopslippers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@heldopslippers](https://www.ruby-forum.com/u/heldopslippers)\
**Post date:** [October 30, 2007, 9:22pm UTC](https://www.ruby-forum.com/t/how-to-call-mutiple-actions-in-one-layout/118736/7 "2007-10-30T21:22:35Z")

</div>

> I would like to render multiple actions in a layout.
> 
> For example:  
> I have in the welcome layout two divs:  
> 1 menubar and a main.
> 
> the menu bar has his one controller with the action: list  
> and the main has a controller (for example: article\_controller.rb) with  
> the action: list.
> 
> both of the actions I want it to be used when the page is loading but i  
> dont now how.  
> I now i can use \<%= yield :layout %\> for the main. But then I dont  
> render the menu.
> 
> can I render the action: list in menu when the page is loaded ?  
> then call the action: list in article…
> 
> I hope you understand my problem (it was hard to explain 😛 )

I don’t think I’d call that rendering multiple “actions,” but rather  
that you have multiple objects you want rendered to the screen.

Eventually you’ll have all kinds of things you want drawn to screen that  
come from multiple objects.

It is the job of the action for the controller of the route to  
instantiate all the objects needed into instance vars which can then be  
used by views, partials, layouts.

Have a look at this article:

[http://www.railsdev.ws/blog/3/modular-page-assembly-in-rails/](http://www.railsdev.ws/blog/3/modular-page-assembly-in-rails/)

It explains techniques for getting data into your layouts.

– gw
