# Multiple Layouts - Single Controller

**URL:** <https://www.ruby-forum.com/t/multiple-layouts-single-controller/98916>\
**Category:** Rails\
**Created:** [July 19, 2006, 12:05am UTC](https://www.ruby-forum.com/t/multiple-layouts-single-controller/98916 "2006-07-19T00:05:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 19, 2006, 12:05am UTC](https://www.ruby-forum.com/t/multiple-layouts-single-controller/98916/1 "2006-07-19T00:05:29Z")

</div>

How do I do multiple layouts for a single controller:

I am aware I can do… render(:layout =\>‘mylayout’) for individual  
actions, however this becomes a multiple render problem.

I tried this…

layout “mylayout”, :except =\> [:myaction, :myotheraction]  
layout “myotherlayout”, :only =\> [:myaction, :myotheraction]

However that doesn’t work, I just get blank layouts for :myaction and  
:myotheraction

Suggestions?

~Jamie

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 19, 2006, 12:11am UTC](https://www.ruby-forum.com/t/multiple-layouts-single-controller/98916/2 "2006-07-19T00:11:45Z")

</div>

On 7/18/06, Jamie Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> However that doesn’t work, I just get blank layouts for :myaction and

layout :choose\_layout

def choose\_layout  
[“myaction”, “myotheraction”].include?(action\_name) ?  
“myotherlayout” : “mylayout”  
end

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 19, 2006, 12:59am UTC](https://www.ruby-forum.com/t/multiple-layouts-single-controller/98916/3 "2006-07-19T00:59:42Z")

</div>

Thanks! I didn’t know that “action\_name” was available

Explanation to others who may be wondering…

# rails will look for a layout named “choose\_layout” and if it doesn’t

find  
it look for an action named “choose\_layout”  
layout :choose\_layout

# define a method that will select the proper layout and make it private

private  
def choose\_layout  
#see if login or signup is the requested action name where  
“action\_name”  
is a variable set by rails.  
[“login”,“signup”].include?(action\_name)  
# if this is true then render “account” otherwise render “standard”  
? “account” : “standard”  
end

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 19, 2006, 1:18am UTC](https://www.ruby-forum.com/t/multiple-layouts-single-controller/98916/4 "2006-07-19T01:18:54Z")

</div>

On 7/18/06, Jamie Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> private  
> def choose\_layout  
> #see if login or signup is the requested action name where “action\_name”  
> is a variable set by rails.  
> [“login”,“signup”].include?(action\_name)  
> # if this is true then render “account” otherwise render “standard”  
> ? “account” : “standard”  
> end

I’m wondering if this would be worth a bug report. As I understand  
you’re supposed to be able to use layout ‘whatever’, :only =\> [‘this’,  
‘that’]. Maybe it’s only in the newest versions though.

---

<div class="post-metadata">

**Author:** ![jamiequint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jamiequint](https://www.ruby-forum.com/u/jamiequint)\
**Post date:** [July 19, 2006, 2:05am UTC](https://www.ruby-forum.com/t/multiple-layouts-single-controller/98916/5 "2006-07-19T02:05:27Z")

</div>

On 7/18/06, Chuck V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> you’re supposed to be able to use layout ‘whatever’, :only =\> [‘this’,  
> ‘that’]. Maybe it’s only in the newest versions though.
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

You can use layout :only and layout :except, but you can only use one  
of them in any given controller. It’s a really common question, and  
it’s worked that way for a long, long time so it’s not a bug. I  
couldn’t tell you the reasoning behind it though.

Pat
