Permalink
Browse files

Fix render partial with layout and no block

When using a render :partial with :layout call, without giving a block,
if the given :partial had another render :partial call, the layout was
not being rendered. This commit fixes this context by storing variables
before rendering the partial, so they are not overrided in any successive
call to render partials down the path. All ActionPack tests are ok.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 3e86e4b commit d5fd83f4c7f01cc1761783408267cce4d5da1946 @carlosantoniodasilva carlosantoniodasilva committed with josevalim Nov 11, 2010
@@ -255,13 +255,15 @@ def render
render_collection
end
else
+ options, locals = @options, @locals
+
content = ActiveSupport::Notifications.instrument("render_partial.action_view",
:identifier => identifier) do
render_partial
end
- if !@block && (layout = @options[:layout])
- content = @view._render_layout(find_template(layout), @locals){ content }
+ if !@block && (layout = options[:layout])
+ content = @view._render_layout(find_template(layout), locals){ content }
end
content
@@ -17,7 +17,7 @@ def render(options = {}, locals = {}, &block)
case options
when Hash
if block_given?
- _render_partial(options.merge(:partial => options[:layout]), &block)
+ _render_partial(options.merge(:partial => options.delete(:layout)), &block)
elsif options.key?(:partial)
_render_partial(options)
else
@@ -0,0 +1,2 @@
+<%= render 'test/partial' %>
+partial with partial
@@ -258,6 +258,16 @@ def test_render_layout_with_block_which_renders_another_partial_and_yields
@view.render(:layout => "layouts/partial_and_yield") { "Content from block!" }
end
+ def test_render_partial_and_layout_without_block_with_locals
+ assert_equal %(Before (Foo!)\npartial html\nAfter),
+ @view.render(:partial => 'test/partial', :layout => 'test/layout_for_partial', :locals => { :name => 'Foo!'})
+ end
+
+ def test_render_partial_and_layout_without_block_with_locals_and_rendering_another_partial
+ assert_equal %(Before (Foo!)\npartial html\npartial with partial\n\nAfter),
+ @view.render(:partial => 'test/partial_with_partial', :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 d5fd83f

Please sign in to comment.