aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2010-10-08 11:12:11 +1300
committerMichael Koziarski <michael@koziarski.com>2010-10-08 11:12:11 +1300
commit581b2b68368e3330cc725a305d0e2465c2e71e1c (patch)
tree6e6e6df132e6e9334f29bbf2f738b0bd7531be81
parentc7760809bfc8e19362272b71b23a294d48195d65 (diff)
downloadrails-581b2b68368e3330cc725a305d0e2465c2e71e1c.tar.gz
rails-581b2b68368e3330cc725a305d0e2465c2e71e1c.tar.bz2
rails-581b2b68368e3330cc725a305d0e2465c2e71e1c.zip
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
-rw-r--r--actionpack/lib/action_view/render/partials.rb10
-rw-r--r--actionpack/test/fixtures/test/_object_inspector.erb1
-rw-r--r--actionpack/test/template/render_test.rb4
3 files changed, 12 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb
index 24d9e9ffb5..4e03d43358 100644
--- a/actionpack/lib/action_view/render/partials.rb
+++ b/actionpack/lib/action_view/render/partials.rb
@@ -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
diff --git a/actionpack/test/fixtures/test/_object_inspector.erb b/actionpack/test/fixtures/test/_object_inspector.erb
new file mode 100644
index 0000000000..53af593821
--- /dev/null
+++ b/actionpack/test/fixtures/test/_object_inspector.erb
@@ -0,0 +1 @@
+<%= object_inspector.inspect -%> \ No newline at end of file
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 205fdcf345..756d8d05d2 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -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