# Inexperienced user needs advice with layouts

**URL:** <https://www.ruby-forum.com/t/inexperienced-user-needs-advice-with-layouts/115532>\
**Category:** Rails\
**Created:** [September 26, 2007, 12:33am UTC](https://www.ruby-forum.com/t/inexperienced-user-needs-advice-with-layouts/115532 "2007-09-26T00:33:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [September 26, 2007, 12:33am UTC](https://www.ruby-forum.com/t/inexperienced-user-needs-advice-with-layouts/115532/1 "2007-09-26T00:33:18Z")

</div>

I’m **thinking** that I want three levels of layouts: one level for the  
application, one level for each controller, and a third for each action.  
The top (application) would define the overall page with the header,  
side panels, maybe tabs. The second would define these areas further  
like what tabs. And the third would fill in the detailed content.

Rails has two of these with layout and templates by default.

Given that Rails has only two levels, is this really what I want and I’m  
just confused thinking I want a third level? It just seems like most of  
each of the controller’s layouts will be a lot of duplication.

If not, and a third level is a good idea, are there any suggestions of  
how to do it in a “Rails” way?

Thank you for your time,  
Perry

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [September 26, 2007, 4:51am UTC](https://www.ruby-forum.com/t/inexperienced-user-needs-advice-with-layouts/115532/2 "2007-09-26T04:51:52Z")

</div>

> I’m **thinking** that I want three levels of layouts: one level for the  
> application, one level for each controller, and a third for each action.

You want both a _layout_ and a _view_ for each action? I’m not sure  
that  
makes much sense to me… why not just merge it all into the view?

As for having a layout per controller, you could have a single master  
layout that contained a call such as:

render :partial =\> “layouts/#{@controller\_name}”

or some such…

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [September 26, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/inexperienced-user-needs-advice-with-layouts/115532/3 "2007-09-26T16:46:37Z")

</div>

Philip H. wrote:

> > I’m **thinking** that I want three levels of layouts: one level for the  
> > application, one level for each controller, and a third for each action.
> 
> You want both a _layout_ and a _view_ for each action? I’m not sure  
> that  
> makes much sense to me… why not just merge it all into the view?

I think a better way to think of it is that I want two levels of  
layouts, a global layout for the application and then a sub-layout per  
controller.

What I came up with so far is that I have the normal layout per  
controller but they call application helpers that create most of the top  
level layout. The parameters that the per controller layout pass to the  
application helpers define the specifics of the layout for that  
controller.

That seems to be working o.k. so far.

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [September 26, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/inexperienced-user-needs-advice-with-layouts/115532/4 "2007-09-26T22:48:12Z")

</div>

On 9/25/07, Perry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> just confused thinking I want a third level? It just seems like most of  
> each of the controller’s layouts will be a lot of duplication.
> 
> If not, and a third level is a good idea, are there any suggestions of  
> how to do it in a “Rails” way?

You’re not the first to think of this. Here’s a good article:

[http://www.marklunds.com/articles/one/360](http://www.marklunds.com/articles/one/360)
