Skip to content
Browse files

Allow layout to access current object being rendered when using rende…

…r partial + object
  • Loading branch information...
1 parent e72374d commit d0c9c93c4a3a7da27ab8d9f53811960309f8e18f @carlosantoniodasilva carlosantoniodasilva committed
View
2 actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -304,7 +304,7 @@ def render_partial
object, as = @object, @variable
if !block && (layout = @options[:layout])
- layout = find_template(layout)
+ layout = find_template(layout, @locals.keys + [@variable])
end
object ||= locals[as]
View
4 actionpack/test/template/render_test.rb
@@ -242,6 +242,10 @@ def test_render_partial_with_layout_using_collection_and_template_makes_current_
assert_equal '<b class="amazon">Hello: Amazon</b><b class="yahoo">Hello: Yahoo</b>', @view.render(:partial => "test/customer", :layout => 'test/b_layout_for_partial_with_object', :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ])
end
+ def test_render_partial_with_layout_using_object_and_template_makes_object_available_in_template
+ assert_equal '<b class="amazon">Hello: Amazon</b>', @view.render(:partial => "test/customer", :layout => 'test/b_layout_for_partial_with_object', :object => Customer.new("Amazon"))
+ end
+
def test_render_partial_with_empty_array_should_return_nil
assert_nil @view.render(:partial => [])
end

0 comments on commit d0c9c93

Please sign in to comment.
Something went wrong with that request. Please try again.