1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

When rendering layouts with blocks, use #capture to avoid assuming that the return value is the block's content.

Signed-off-by: Yehuda Katz <wycats@Yehuda-Katz.local>
This commit is contained in:
Nathan Weizenbaum 2009-11-05 20:07:14 -08:00 committed by Yehuda Katz
parent cb9a1759c0
commit cbded53671
2 changed files with 3 additions and 5 deletions

View file

@ -71,12 +71,10 @@ module ActionView
# In this case, the layout would receive the block passed into <tt>render :layout</tt>,
# and the Struct specified in the layout would be passed into the block. The result
# would be <html>Hello David</html>.
def _layout_for(name = nil)
def _layout_for(name = nil, &block)
return @_content_for[name || :layout] if !block_given? || name
with_output_buffer do
return yield
end
capture(&block)
end
def _render_inline(inline, layout, options)

View file

@ -1,3 +1,3 @@
<% render(:layout => "layout_for_partial", :locals => { :name => "Anthony" }) do %>Inside from first block in layout<% end %>
<% render(:layout => "layout_for_partial", :locals => { :name => "Anthony" }) do %>Inside from first block in layout<% "Return value should be discarded" %><% end %>
<%= yield %>
<% render(:layout => "layout_for_partial", :locals => { :name => "Ramm" }) do %>Inside from second block in layout<% end %>