我正在寻找的效果是为html框实现可重用组件。我发现人们似乎使用类似下面的例子,但它不适合我。 我:渲染局部布局不显示任何内容
# app/views/home/index.html.erb
top
<% render :layout => 'layouts/box' do %>
<p>Here is some content</p>
<% end %>
bottom
和
# app/views/layouts/_box.html.erb
inside box
<%= yield %>
最终的结果我得到呈现在浏览器上是:
top bottom
,我仍然可以在日志中看到:
Processing by HomeController#index as HTML
Rendered layouts/_box.html.erb (0.1ms)
Rendered home/index.html.erb within layouts/application (1.2ms)
所以箱子布局正在处理中。它只是没有显示任何东西。 任何想法?
我使用的是Rails 3.1.3和Ruby 1.9.2-p290。
你忘了打印渲染。使用<%= render代替<%render – yoavmatchulsky