Andrew Edwards
2006-Aug-05 10:51 UTC
[Rails] yield :layout, add extra content at controller level
Hi, Could someone point me in the right direction for specifying content at the controller level so that I could use something similar to "yield :left_nav_content" as well as "yield :layout" in my layouts? I know I can specifiy this content in my view using something like: <% content_for("left_nav_content") do %> <h1>Some Menu Options</h1> <% end %> However I would need to repeat this in each view for a particular controller. Any pointers on where to start looking at the ActionController source to understand how this mechanism works greatly received. Andrew. -- Posted via http://www.ruby-forum.com/.
Zack Chandler
2006-Aug-05 15:49 UTC
[Rails] yield :layout, add extra content at controller level
Andrew, If you need to repeat a content block in numerous views I would recommend simply creating another layout for those actions to use. Hope this helps, Zack On 8/5/06, Andrew Edwards <andrew@shavers.co.uk> wrote:> Hi, > > Could someone point me in the right direction for specifying content at > the controller level so that I could use something similar to "yield > :left_nav_content" as well as "yield :layout" in my layouts? > > I know I can specifiy this content in my view using something like: > > <% content_for("left_nav_content") do %> > <h1>Some Menu Options</h1> > <% end %> > > However I would need to repeat this in each view for a particular > controller. Any pointers on where to start looking at the > ActionController source to understand how this mechanism works greatly > received. > > Andrew. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Andrew Edwards
2006-Aug-05 16:09 UTC
[Rails] Re: yield :layout, add extra content at controller level
Zack Chandler wrote:> Andrew, > > If you need to repeat a content block in numerous views I would > recommend simply creating another layout for those actions to use. > > Hope this helps, > ZackHi Zack, This was the path I was taking but found that there was a lot of repeated code as each controller only required a different left hand menu. Ideally I would like to be able to stack layouts, which unfortunately it not a feature I am aware of. I have taken this opportunity to learn more about the plugins and am seeing if there is any way I could augment the ActionController to give an easily reversed temporary solution. I''m still learning ruby so get a bit lost when trying to follow some of the rails ActionController and ActionView relationships. All I really need is to pass the name of a partial to the layout so that it can insert it in the left hand column. Unless a plugin exists that does something similar? It just seems such a waste to duplicate a bunch of layouts just for the difference of a single section. I suppose I could pass in the menu via a partial using the content_for helper in each view but it''s similarly anti-DRY given multiple actions for a controller. Andrew. -- Posted via http://www.ruby-forum.com/.