# \*Very\* basic layout question

**URL:** <https://www.ruby-forum.com/t/very-basic-layout-question/63960>\
**Category:** Rails\
**Created:** [January 22, 2006, 3:44pm UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960 "2006-01-22T15:44:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 22, 2006, 3:44pm UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960/1 "2006-01-22T15:44:56Z")

</div>

I’m trying to use a different layout for just one action in my  
controller, all the other actions use the application.rhtml layout, so  
what i’m doing is …

class SomeController \< ApplicationController  
layout “simple”, :only=\> :some\_action

```
......

```

end

and the “simple” layout is applied to all the actions, can someone  
please give me a hint?

Thanks for everything. I’m loving rails so far, loving the comunity =).

---

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 22, 2006, 4:27pm UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960/2 "2006-01-22T16:27:18Z")

</div>

On Jan 22, 2006, at 15:43, Santiago Hirschfeld wrote:

> I’m trying to use a different layout for just one action in my  
> controller, all the other actions use the application.rhtml layout,

I’m not sure why what you already have doesn’t work, but instead just  
do render(:action =\> ‘some\_action’, :layout =\> ‘simple’) in your action.

–  
Jakob S. - [http://mentalized.net](http://mentalized.net)

---

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 22, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960/3 "2006-01-22T16:39:29Z")

</div>

Thanks, I did

def some\_action  
…  
render(:action =\> ‘some\_action’, :layout =\> ‘simple’)  
end

And it worked fine, but i wonder if there is right to render an action  
from the same action =) sorry for another stupid question, but I’m  
curious.

Thank you for, very much.

2006/1/22, Jakob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 22, 2006, 5:22pm UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960/4 "2006-01-22T17:22:08Z")

</div>

Santiago Hirschfeld wrote:

> Thanks, I did
> 
> def some\_action  
> …  
> render(:action =\> ‘some\_action’, :layout =\> ‘simple’)  
> end
> 
> And it worked fine, but i wonder if there is right to render an action  
> from the same action =) sorry for another stupid question, but I’m  
> curious.

Yeah, it’s fine this way. Basically, Rails will do just that for you if  
you don’t yourself. Doing it yourself just gives you a bit more control

- and code.

---

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 22, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960/5 "2006-01-22T18:01:43Z")

</div>

Thanks for all the quick and usefull answers!

I got it working fine now, thanks again.

2006/1/22, Michiel S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 22, 2006, 5:52pm UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960/6 "2006-01-22T17:52:34Z")

</div>

2006/1/22, Jakob L. Skjerning [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > curious.
> 
> Yeah, it’s fine this way. Basically, Rails will do just that for you if  
> you don’t yourself. Doing it yourself just gives you a bit more control
> 
> - and code.

To make the code look nicer, you can also just use render :layout =\>  
‘simple’. Which renders the current action with the ‘simple’ layout.

---

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 30, 2006, 7:29am UTC](https://www.ruby-forum.com/t/very-basic-layout-question/63960/7 "2006-01-30T07:29:39Z")

</div>

If I have in application\_controller.rb:

layout ‘standard’

and in some\_controller.rb

layout ‘special’, :only=\>[:a, :b, :c]

All other actions in some\_controller will use NO template at all, rather  
than using the ‘standard’ layout specified in application.rb. Actions  
not in :only, or in :except should inherit application.rb’s layout IMO.

csn
