Browse files

fix rendering a partial with an array as its :object [#5746 state:res…

…olved]

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 5e685ca commit 2ded862226e1309fc8042b824d388e5bf927d357 @jamesmacaulay jamesmacaulay committed with NZKoz Sep 30, 2010
View
10 actionpack/lib/action_view/render/partials.rb
@@ -237,7 +237,7 @@ def setup(options, block)
else
@object = partial
- if @collection = collection
+ if @collection = collection_from_object || collection
paths = @collection_paths = @collection.map { |o| partial_path(o) }
@path = paths.uniq.size == 1 ? paths.first : nil
else
@@ -336,10 +336,14 @@ def render_partial(object = @object)
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
1 actionpack/test/fixtures/test/_object_inspector.erb
@@ -0,0 +1 @@
+<%= object_inspector.inspect -%>
View
4 actionpack/test/template/render_test.rb
@@ -129,6 +129,10 @@ def test_render_object
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

0 comments on commit 2ded862

Please sign in to comment.