# Layouts

**URL:** <https://www.ruby-forum.com/t/layouts/99348>\
**Category:** Rails\
**Created:** [July 21, 2006, 10:01pm UTC](https://www.ruby-forum.com/t/layouts/99348 "2006-07-21T22:01:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 21, 2006, 10:01pm UTC](https://www.ruby-forum.com/t/layouts/99348/1 "2006-07-21T22:01:31Z")

</div>

I am trying to set the layout for certain actions within a controller,  
but not others, but doing  
class JoinController \< ApplicationController  
layout ‘form’  
def index  
end  
def add  
end  
end  
sets layouts for all actions, and doing  
class JoinController \< ApplicationController  
def index  
layout ‘form’  
end  
def add  
end  
end  
returns an error. Is there any way I can set the layout ‘form’ for the  
index action, but not the add action? Thanks, I can’t find any other way  
to call layouts .

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 21, 2006, 10:13pm UTC](https://www.ruby-forum.com/t/layouts/99348/2 "2006-07-21T22:13:31Z")

</div>

In the actions where you want a different layout try:

def index  
…  
render :layout =\> ‘differentname’  
end

HTH,  
Jeff

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 21, 2006, 10:16pm UTC](https://www.ruby-forum.com/t/layouts/99348/3 "2006-07-21T22:16:41Z")

</div>

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

> Is there any way I can set the layout ‘form’ for the  
> index action, but not the add action? Thanks, I can’t find any other way  
> to call layouts .

layout “form”, :except =\> [:add]

– OR –

layout “form”, :only =\> [:index]

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 21, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/layouts/99348/4 "2006-07-21T22:47:18Z")

</div>

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

> Actually I tried an “except”, but I guess I forgot a comma and a [.  
> Oops. I’m kinda new to rails, and the syntax is so different from my  
> native cf. Thanks,

Probably the comma. The array isn’t required, but I did it that way  
to show you that you could put more than one symbol in there if you  
wanted to.

– James

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 21, 2006, 10:26pm UTC](https://www.ruby-forum.com/t/layouts/99348/5 "2006-07-21T22:26:37Z")

</div>

Actually I tried an “except”, but I guess I forgot a comma and a [.  
Oops. I’m kinda new to rails, and the syntax is so different from my  
native cf. Thanks,  
Ben.

> layout “form”, :except =\> [:add]
> 
> – OR –
> 
> layout “form”, :only =\> [:index]

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 21, 2006, 10:50pm UTC](https://www.ruby-forum.com/t/layouts/99348/6 "2006-07-21T22:50:32Z")

</div>

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

> Actually I tried an “except”, but I guess I forgot a comma and a [.  
> Oops. I’m kinda new to rails, and the syntax is so different from my  
> native cf. Thanks,  
> Ben.

FYI

[http://api.rubyonrails.org/](http://api.rubyonrails.org/)

Click on “layout” under “Methods.”

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 22, 2006, 5:40am UTC](https://www.ruby-forum.com/t/layouts/99348/7 "2006-07-22T05:40:50Z")

</div>

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

> > FYI
> > 
> > [http://api.rubyonrails.org/](http://api.rubyonrails.org/)
> > 
> > Click on “layout” under “Methods.”
> 
> I wonder if the API is helpful to Rails newbies. I tend to think not –  
> it wasn’t for me and I’ve read about others complaints. Are there  
> people who find the API a good place to learn about Rails?

To learn Rails? No.

To answer a question about the syntax of a specific method, such as  
“layout”? Yeah.

– James

---

<div class="post-metadata">

**Author:** ![ben-v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecb155/32.png) [@ben-v](https://www.ruby-forum.com/u/ben-v)\
**Post date:** [July 22, 2006, 4:27am UTC](https://www.ruby-forum.com/t/layouts/99348/8 "2006-07-22T04:27:18Z")

</div>

> FYI
> 
> [http://api.rubyonrails.org/](http://api.rubyonrails.org/)
> 
> Click on “layout” under “Methods.”

I wonder if the API is helpful to Rails newbies. I tend to think not –  
it wasn’t for me and I’ve read about others complaints. Are there  
people who find the API a good place to learn about Rails?
