Simple nested_layout for rails

There are some 40loc nested layout monsters on the interwebs, but it can be as simple as…

# application_helper.rb
def nested_layout(layout, &block)
  @content_for_layout = capture(&block)
  concat(render :file => layout)
end

# layouts/xxxx.erb
<% nested_layout 'layouts/application' do %>
  Im nested...
  <%= yield %>
<% end %>

Leave a comment