Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure @content_for_* is checked before yielding to block in render :…

…layout [#8994 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit 4ad5aa9a39a83863331a7665407dac475855765b 1 parent 4684e76
@ryanb ryanb authored josh committed
View
2  actionpack/lib/action_view/renderable.rb
@@ -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)
View
2  actionpack/test/fixtures/layouts/_column.html.erb
@@ -0,0 +1,2 @@
+<div id="column"><%= yield :column %></div>
+<div id="content"><%= yield %></div>
View
3  actionpack/test/fixtures/test/nested_layout.erb
@@ -0,0 +1,3 @@
+<% content_for :title, "title" -%>
+<% content_for :column do -%>column<% end -%>
+<% render :layout => 'layouts/column' do -%>content<% end -%>
View
10 actionpack/test/template/render_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.