tag:blogger.com,1999:blog-7216094495459361823.post1168767326815295751..comments2010-04-22T00:46:45.084-07:00Comments on Stumbling into the World of Ruby on Rails: Nested Layouts in RailsAcaphttp://www.blogger.com/profile/17295793947500084663noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-7216094495459361823.post-87489336472990663622008-10-07T03:27:00.000-07:002008-10-07T03:27:00.000-07:00Just wanted to say THANKS for your great solution ...Just wanted to say THANKS for your great solution - exactly what I needed.<BR/>Works perfect!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7216094495459361823.post-83430040133325027192008-09-11T13:17:00.000-07:002008-09-11T13:17:00.000-07:00I didn't need a new nested layout for every co...I didn't need a new nested layout for every controller, just a few. Well, one to start. Simply wrapping the render :partial with a block and catching the MissingTemplate, where you drop back to yield, (seems to) work great:<BR/><BR/><%= begin; render :partial => "layouts/#{controller.controller_name}"; rescue ActionView::MissingTemplate; yield; end %>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7216094495459361823.post-73097660143246895702008-08-22T15:16:00.000-07:002008-08-22T15:16:00.000-07:00You can take this a step further.If you want to mi...You can take this a step further.<BR/><BR/>If you want to mix and match your "layouts" (which are really just partials, let's face it) across arbitrary controller/action pairs, you can just define a special variable, say @inner_layout.<BR/><BR/>And then in each action that you want to use the inner layout, you just define it.<BR/><BR/>So in your application.html.erb:<BR/><BR/><%= @inner_layout ? render(:partial => "layouts/#{@inner_layout}") : yield %><BR/><BR/>If there's an inner "layout" (partial) then render it (assuming that it will yield), and if there isn't one, just go ahead and yield.<BR/><BR/>And then in the appropriate action(s): <BR/><BR/>@inner_layout = 'some_inner_layout_filename'.<BR/><BR/>Although the variable thing is a bit of a drag, you could take this as far as you want.Anonymousnoreply@blogger.com