# Layouts and content\_for

**URL:** <https://www.ruby-forum.com/t/layouts-and-content-for/148818>\
**Category:** Rails\
**Created:** [September 17, 2008, 11:17am UTC](https://www.ruby-forum.com/t/layouts-and-content-for/148818 "2008-09-17T11:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostwarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@lostwarrior](https://www.ruby-forum.com/u/lostwarrior)\
**Post date:** [September 17, 2008, 11:17am UTC](https://www.ruby-forum.com/t/layouts-and-content-for/148818/1 "2008-09-17T11:17:28Z")

</div>

when i studied the tutorial about layouts & content\_for from railscast.I  
need a clarification as per their tutorial.

url:[#8 Layouts and content\_for - RailsCasts](http://railscasts.com/episodes/8-layouts-and-content-for)

\<!- projects/index.rhtml →   
\<% content\_for :head do %\> \<= stylesheet\_link\_tag â€˜projectsâ€™ %\>  
\< end %\>

\<!- layouts/application.rhtml →

 Todo List \<%= stylesheet\_link\_tag â€˜applicationâ€™ %\> \<%= yield :head %\>

As per the tutorial they are calling the yiel:head & content\_for :head  
has been written in index.html.erb.

My question is if i want to call another yield such as yield :footer and  
if i write content\_for :footer in some other file like footer.html.erb.  
Then in my layout yield :footer is not taking.

Please give me some suggestions regarding this

Thanks in advance

---

<div class="post-metadata">

**Author:** ![lostwarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@lostwarrior](https://www.ruby-forum.com/u/lostwarrior)\
**Post date:** [September 17, 2008, 1:12pm UTC](https://www.ruby-forum.com/t/layouts-and-content-for/148818/2 "2008-09-17T13:12:51Z")

</div>

You have to keep in mind how views are being called:

- The browser makes a request to a URL
- The Rails routing rules determine which controller/action the URL  
resolves to
- The action is called
- The corresponding view (assuming the action doesn’t redirect to a  
new action) is being called
- The controller (usually) determines which layout is to be used
- The view is displayed together with the layout.

So: if you have an index.html.erb view being displayed, together with  
the layout application.html.erb, that’s all that will be displayed. If  
your view doesn’t define content\_for for all the parts listed in you  
layout (with yield), those symbols remain undefined (nil) and don’t  
display. Which is why your :footer part isn’t displayed, there is  
nothing telling rails to display the footer.html.erb template.

If you want to render a footer partial, you can use \<%=  
render :partial =\> shared/footer %\> for example. That will actually  
include the shared/\_footer.html.erb template in your page.

On 17 sep, 11:17, Lost W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![lostwarrior](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@lostwarrior](https://www.ruby-forum.com/u/lostwarrior)\
**Post date:** [September 17, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/layouts-and-content-for/148818/3 "2008-09-17T13:14:57Z")

</div>

deegee wrote:

> You have to keep in mind how views are being called:
> 
> - The browser makes a request to a URL
> - The Rails routing rules determine which controller/action the URL  
> resolves to
> - The action is called
> - The corresponding view (assuming the action doesn’t redirect to a  
> new action) is being called
> - The controller (usually) determines which layout is to be used
> - The view is displayed together with the layout.
> 
> So: if you have an index.html.erb view being displayed, together with  
> the layout application.html.erb, that’s all that will be displayed. If  
> your view doesn’t define content\_for for all the parts listed in you  
> layout (with yield), those symbols remain undefined (nil) and don’t  
> display. Which is why your :footer part isn’t displayed, there is  
> nothing telling rails to display the footer.html.erb template.
> 
> If you want to render a footer partial, you can use \<%=  
> render :partial =\> shared/footer %\> for example. That will actually  
> include the shared/\_footer.html.erb template in your page.
> 
> On 17 sep, 11:17, Lost W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks for ur reply.  
After made the post i just found the result.thanks for ur suggestion
