Permalink
Browse files

Fix rendering partial with layout, when the partial contains another …

…render layout with block call

In such situations, the first layout was not being applied. This fixes it by
storing the block variable before rendering the partial, so the variable
is not overrided, thus the layout is applied (bear in mind the renderer is
shared among all render calls).

This commit also adds some more tests to render partials with layouts and
nested render layout calls.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent b870193 commit bdec56cbe74c53482f150829f735e45e9f7afeb7 @carlosantoniodasilva carlosantoniodasilva committed with spastorino Nov 13, 2010
@@ -255,14 +255,14 @@ def render
render_collection
end
else
- options, locals = @options, @locals
+ block, options, locals = @block, @options, @locals
content = ActiveSupport::Notifications.instrument("render_partial.action_view",
:identifier => identifier) do
render_partial
end
- if !@block && (layout = options[:layout])
+ if !block && (layout = options[:layout])
content = @view._render_layout(find_template(layout), locals){ content }
end
@@ -0,0 +1,2 @@
+<%= render :partial => 'test/partial', :layout => 'test/layout_for_partial', :locals => { :name => 'Bar!' } %>
+partial with layout
@@ -0,0 +1,4 @@
+<%= render :layout => 'test/layout_for_partial', :locals => { :name => 'Bar!' } do %>
+ Content from inside layout!
+<% end %>
+partial with layout
@@ -0,0 +1,4 @@
+<%= render :layout => 'test/layout_for_partial', :locals => { :name => 'Bar!' } do %>
+ <%= render 'test/partial' %>
+<% end %>
+partial with layout
@@ -268,6 +268,22 @@ def test_render_partial_and_layout_without_block_with_locals_and_rendering_anoth
@view.render(:partial => 'test/partial_with_partial', :layout => 'test/layout_for_partial', :locals => { :name => 'Foo!'})
end
+ def test_render_layout_with_a_nested_render_layout_call
+ assert_equal %(Before (Foo!)\nBefore (Bar!)\npartial html\nAfter\npartial with layout\n\nAfter),
+ @view.render(:partial => 'test/partial_with_layout', :layout => 'test/layout_for_partial', :locals => { :name => 'Foo!'})
+ end
+
+ def test_render_layout_with_a_nested_render_layout_call_using_block_with_render_partial
+ assert_equal %(Before (Foo!)\nBefore (Bar!)\n\n partial html\n\nAfterpartial with layout\n\nAfter),
+ @view.render(:partial => 'test/partial_with_layout_block_partial', :layout => 'test/layout_for_partial', :locals => { :name => 'Foo!'})
+ end
+
+ def test_render_layout_with_a_nested_render_layout_call_using_block_with_render_content
+ #debugger
+ assert_equal %(Before (Foo!)\nBefore (Bar!)\n\n Content from inside layout!\n\nAfterpartial with layout\n\nAfter),
+ @view.render(:partial => 'test/partial_with_layout_block_content', :layout => 'test/layout_for_partial', :locals => { :name => 'Foo!'})
+ end
+
# TODO: Move to deprecated_tests.rb
def test_render_with_nested_layout_deprecated
assert_deprecated do

0 comments on commit bdec56c

Please sign in to comment.