# Layout question

**URL:** <https://www.ruby-forum.com/t/layout-question/49292>\
**Category:** Rails\
**Created:** [December 2, 2005, 5:36am UTC](https://www.ruby-forum.com/t/layout-question/49292 "2005-12-02T05:36:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 2, 2005, 5:36am UTC](https://www.ruby-forum.com/t/layout-question/49292/1 "2005-12-02T05:36:20Z")

</div>

Hi:

If I have four controllers and I want them to use a common layout, I  
believe there is a way to do that, I read about it once. To have one  
layout that covers all the controllers in an application.

Could someone kindly tell me how that is done? do you create a  
single rhtml file called application. rhtml and drop it at the root  
level of the view controller?

bruce

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 2, 2005, 5:44am UTC](https://www.ruby-forum.com/t/layout-question/49292/2 "2005-12-02T05:44:29Z")

</div>

On Thu, Dec 01, 2005 at 09:35:30PM -0700, Bruce B. wrote:

> Hi:
> 
> If I have four controllers and I want them to use a common layout, I  
> believe there is a way to do that, I read about it once. To have one  
> layout that covers all the controllers in an application.
> 
> Could someone kindly tell me how that is done? do you create a  
> single rhtml file called application. rhtml and drop it at the root  
> level of the view controller?

Yes, create a layout called application.rhtml. The conventions for  
layouts,  
among several, include looking for a layout with the same name as the  
current  
controller. Then, looking for one called application.rhtml. Put it in  
app/views/layouts. If you go off of the naming convention then you must  
not  
use the “layout” macro in your controller.

marcel

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 2, 2005, 6:12am UTC](https://www.ruby-forum.com/t/layout-question/49292/3 "2005-12-02T06:12:50Z")

</div>

The answer - straight from the Agile Web Dev book is:

If you create a layout called application in the layouts directory, it  
will be applied to all controllers that donâ??t otherwise have a layout  
defined  
for them.

bruce

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 2, 2005, 2:33pm UTC](https://www.ruby-forum.com/t/layout-question/49292/4 "2005-12-02T14:33:53Z")

</div>

Thank you Marcel.

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 2, 2005, 2:37pm UTC](https://www.ruby-forum.com/t/layout-question/49292/5 "2005-12-02T14:37:59Z")

</div>

The answer - straight from the Agile Web Dev book is:

If you create a layout called application in the layouts directory, it  
will be applied to all controllers that donâ??t otherwise have a layout  
defined  
for them.

bruce

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 2, 2005, 5:48am UTC](https://www.ruby-forum.com/t/layout-question/49292/6 "2005-12-02T05:48:31Z")

</div>

Hi Bruce,

I think in you ApplicationController

you would put

layout :somelayout

eg

class ApplicationController \< ActionController::Base

layout :somelayout

other stuff

end

Cheers
