fix rendering a partial with an array as its :object [#5746 state:resolved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>

Conflicts:

	actionpack/lib/action_view/render/partials.rb
This commit is contained in:
Michael Koziarski
2010-10-08 11:12:11 +13:00
parent c7760809bf
commit 581b2b6836
3 changed files with 12 additions and 3 deletions

View File

@@ -235,7 +235,7 @@ module ActionView
else
@object = partial
if @collection = collection
if @collection = collection_from_object || collection
paths = @collection_data = @collection.map { |o| partial_path(o) }
@path = paths.uniq.size == 1 ? paths.first : nil
else
@@ -337,10 +337,14 @@ module ActionView
private
def collection
if @options.key?(:collection)
@options[:collection] || []
end
end
def collection_from_object
if @object.respond_to?(:to_ary)
@object
elsif @options.key?(:collection)
@options[:collection] || []
end
end

View File

@@ -0,0 +1 @@
<%= object_inspector.inspect -%>

View File

@@ -127,6 +127,10 @@ module RenderTestCases
assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david"))
end
def test_render_object_with_array
assert_equal "[1, 2, 3]", @view.render(:partial => "test/object_inspector", :object => [1, 2, 3])
end
def test_render_partial_collection
assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
end