ruby-on-rails – 在Rails中嵌套布局

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 在Rails中嵌套布局前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以在Rails 3.2中嵌套布局?我想创建application.html.erb使用的通用布局,并允许应用程序中的几个视图使用它.我找到了 Nested Layouts颗ruby,但它在四年内没有更新.如果我可以在application.html.erb文件中执行以下操作,那将是非常棒的:

<% inside_layout 'html5_boilerplate' do %>
  <div id="container">
    <%= yield %>
  </div>
<% end %>

解决方法

我在 this blog post找到了一个简单的解决方案.

在我的ApplicationHelper中,我添加了以下内容

def parent_layout(layout)
  @view_flow.set(:layout,output_buffer)
  self.output_buffer = render(:file => "layouts/#{layout}")
end

在application.html.erb中,我添加了:

<% parent_layout 'html5_boilerplate' %>

猜你在找的Ruby相关文章