1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Adds :layout option to render :partial when a collection is given.

This commit is contained in:
Sergio Arbeo 2012-03-06 16:20:56 +01:00
parent dc80715207
commit e4e1388318
3 changed files with 14 additions and 1 deletions

View file

@ -238,7 +238,14 @@ module ActionView
spacer = find_template(@options[:spacer_template]).render(@view, @locals)
end
if layout = @options[:layout]
layout = find_template(layout)
end
result = @template ? collection_with_template : collection_without_template
result.map!{|content| layout.render(@view, @locals) { content } } if layout
result.join(spacer).html_safe
end
@ -342,9 +349,10 @@ module ActionView
locals[as] = object
segments << template.render(@view, locals)
end
segments
end
def collection_without_template
segments, locals, collection_data = [], @locals, @collection_data

View file

@ -0,0 +1 @@
<b><%= yield %></b>

View file

@ -238,6 +238,10 @@ module RenderTestCases
def test_render_partial_with_nil_values_in_collection
assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ])
end
def test_render_partial_with_layout_using_collection_and_template
assert_equal "<b>Hello: Amazon</b><b>Hello: Yahoo</b>", @view.render(:partial => "test/customer", :layout => 'test/b_layout_for_partial', :collection => [ Customer.new("Amazon"), Customer.new("Yahoo") ])
end
def test_render_partial_with_empty_array_should_return_nil
assert_nil @view.render(:partial => [])