mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
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:
@@ -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
|
||||
|
||||
|
||||
1
actionpack/test/fixtures/test/_object_inspector.erb
vendored
Normal file
1
actionpack/test/fixtures/test/_object_inspector.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<%= object_inspector.inspect -%>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user