# Question about layout

**URL:** <https://www.ruby-forum.com/t/question-about-layout/99611>\
**Category:** Rails\
**Created:** [July 24, 2006, 2:40pm UTC](https://www.ruby-forum.com/t/question-about-layout/99611 "2006-07-24T14:40:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukasz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@Lukasz](https://www.ruby-forum.com/u/Lukasz)\
**Post date:** [July 24, 2006, 2:40pm UTC](https://www.ruby-forum.com/t/question-about-layout/99611/1 "2006-07-24T14:40:54Z")

</div>

Hey,

I couldn’t find answer for this question for quite long, I hope some  
one will explain to me why layout specified in application.rb is not  
displayed properly on all views? I mean some divs are displayed wrong  
or without layout at all… let’s say login.rhtml has layout on its own  
and now it works ( exactly this same as project.rhtml which is layout  
for the whole project… ) but when I have this layout “project” in  
login\_controller it does not work ( it is from app.rb ) So why is it so?  
That some views are not displaying layout correctly at all or just  
partialy ?

Thanks a million  
Lukasz

---

<div class="post-metadata">

**Author:** ![Lukasz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@Lukasz](https://www.ruby-forum.com/u/Lukasz)\
**Post date:** [July 24, 2006, 4:38pm UTC](https://www.ruby-forum.com/t/question-about-layout/99611/2 "2006-07-24T16:38:57Z")

</div>

Hi Lukasz,

Lukasz wrote:

> I mean some divs are displayed wrong  
> or without layout at all… let’s say login.rhtml has layout on its own  
> and now it works ( exactly this same as project.rhtml which is layout  
> for the whole project… ) but when I have this layout “project” in  
> login\_controller it does not work ( it is from app.rb ) So why is it so?  
> That some views are not displaying layout correctly at all or just  
> partialy ?

I’m not sure this will help since I don’t know much about the details of  
your app and am not sure I understand your problem statement 100%, but  
the  
basic rules for the view-layout hierarchy is that the view file that’s  
rendered will be 1) one in the app/views/ directory that’s named after  
the  
controller action, 2) the one that’s specified by the controller action  
(ie,  
through a render :something), or 3) application.rhtml.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![Lukasz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@Lukasz](https://www.ruby-forum.com/u/Lukasz)\
**Post date:** [July 25, 2006, 12:02am UTC](https://www.ruby-forum.com/t/question-about-layout/99611/3 "2006-07-25T00:02:01Z")

</div>

Hey Bill,

Thanks for response but thats not what I mean - acctualy You are right  
I was not very clear. Here I will try to explain my problem in more  
details.  
I have login controler with login method (so I have  
app/views/login.rhtm) and I have manage\_users controler with delete add  
and edit methods on it … (done by scaffolding) and therefor I need  
them all to share this same layout… I specified layout in  
application.rb but it seems that only manage\_users has it…  
login.rhtml seems to have only some of it (even if it uses this same  
divs! ) I created a new one called login.rhtml inside /app/view/layout  
and it looks fine now but that annoys me cos it will require me to  
create a new layout file for each view which is not what I want 🙂 I  
need them to share one layout…

How it is now ? Thanks again.

Cheers,  
Lukasz

Bill W. wrote:

> Hi Lukasz,
> 
> Lukasz wrote:
> 
> > I mean some divs are displayed wrong  
> > or without layout at all… let’s say login.rhtml has layout on its own  
> > and now it works ( exactly this same as project.rhtml which is layout  
> > for the whole project… ) but when I have this layout “project” in  
> > login\_controller it does not work ( it is from app.rb ) So why is it so?  
> > That some views are not displaying layout correctly at all or just  
> > partialy ?
> 
> I’m not sure this will help since I don’t know much about the details of  
> your app and am not sure I understand your problem statement 100%, but  
> the  
> basic rules for the view-layout hierarchy is that the view file that’s  
> rendered will be 1) one in the app/views/ directory that’s named after  
> the  
> controller action, 2) the one that’s specified by the controller action  
> (ie,  
> through a render :something), or 3) application.rhtml.
> 
> hth,  
> Bill

---

<div class="post-metadata">

**Author:** ![Lukasz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@Lukasz](https://www.ruby-forum.com/u/Lukasz)\
**Post date:** [July 25, 2006, 12:28am UTC](https://www.ruby-forum.com/t/question-about-layout/99611/4 "2006-07-25T00:28:52Z")

</div>

Lukasz, by default all controllers in your app will render  
app/views/layouts/application.rhtml. You don’t need to specify that in  
the application.rb.

In your application.rhtml file you should have the following command in  
the body:

\<%= yield %\>

(previously this was \<%= @content\_for\_layout %\> which should also work.

this will insert into that spot any content in the specific rhtml for  
that controller/method (ie, app/views/login/login.rhtml) if you have a  
controller named login with a method named login.

Lukasz wrote:

> I have login controler with login method (so I have  
> app/views/login.rhtm) and I have manage\_users controler with delete add  
> and edit methods on it … (done by scaffolding) and therefor I need  
> them all to share this same layout… I specified layout in  
> application.rb but it seems that only manage\_users has it…  
> login.rhtml seems to have only some of it (even if it uses this same  
> divs! ) I created a new one called login.rhtml inside /app/view/layout  
> and it looks fine now but that annoys me cos it will require me to  
> create a new layout file for each view which is not what I want 🙂 I  
> need them to share one layout…
