提交 4ad5aa9a 编写于 作者: R Ryan Bates 提交者: Joshua Peek

Ensure @content_for_* is checked before yielding to block in render :layout [#8994 state:resolved]

Signed-off-by: NJoshua Peek <josh@joshpeek.com>
上级 4684e76a
......@@ -36,7 +36,7 @@ def render(view, local_assigns = {})
result = view.send(method_name(local_assigns), local_assigns) do |*names|
ivar = :@_proc_for_layout
if view.instance_variable_defined?(ivar) and proc = view.instance_variable_get(ivar)
if !view.instance_variable_defined?(:"@content_for_#{names.first}") && view.instance_variable_defined?(ivar) && (proc = view.instance_variable_get(ivar))
view.capture(*names, &proc)
elsif view.instance_variable_defined?(ivar = :"@content_for_#{names.first || :layout}")
view.instance_variable_get(ivar)
......
<div id="column"><%= yield :column %></div>
<div id="content"><%= yield %></div>
\ No newline at end of file
<% content_for :title, "title" -%>
<% content_for :column do -%>column<% end -%>
<% render :layout => 'layouts/column' do -%>content<% end -%>
\ No newline at end of file
......@@ -162,4 +162,14 @@ def test_render_inline_with_locals_and_compilable_custom_type
ActionView::Template.register_template_handler :foo, CustomHandler
assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
end
def test_render_with_layout
assert_equal %(<title></title>\nHello world!\n),
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
end
def test_render_with_nested_layout
assert_equal %(<title>title</title>\n<div id="column">column</div>\n<div id="content">content</div>\n),
@view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield")
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册