when i studied the tutorial about layouts & content_for from railscast.I need a clarification as per their tutorial. url:http://railscasts.com/episodes/8-layouts-and-content-for <!- projects/index.rhtml -> <% content_for :head do %> <= stylesheet_link_tag ‘projects’ %> < end %> <!- layouts/application.rhtml -> <head> <title>Todo List</title> <%= stylesheet_link_tag ‘application’ %> <%= yield :head %> </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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Warrior <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> when i studied the tutorial about layouts & content_for from railscast.I > need a clarification as per their tutorial. > > url:http://railscasts.com/episodes/8-layouts-and-content-for > > <!- projects/index.rhtml -> > <% content_for :head do %> <= stylesheet_link_tag ‘projects’ %> > < end %> > > <!- layouts/application.rhtml -> > <head> <title>Todo List</title> <%= stylesheet_link_tag ‘application’ %> > <%= yield :head %> > </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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Warrior <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thanks for ur reply. After made the post i just found the result.thanks for ur suggestion -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---