Skip to content

Commit

Permalink
fix rendering a partial with an array as its :object [#5746 state:res…
Browse files Browse the repository at this point in the history
…olved]

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

Conflicts:

	actionpack/lib/action_view/render/partials.rb
  • Loading branch information
NZKoz committed Oct 7, 2010
1 parent c776080 commit 581b2b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions actionpack/lib/action_view/render/partials.rb
Expand Up @@ -235,7 +235,7 @@ def setup(options, block)
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
Expand Down Expand Up @@ -337,10 +337,14 @@ def render_partial
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

Expand Down
1 change: 1 addition & 0 deletions actionpack/test/fixtures/test/_object_inspector.erb
@@ -0,0 +1 @@
<%= object_inspector.inspect -%>
4 changes: 4 additions & 0 deletions actionpack/test/template/render_test.rb
Expand Up @@ -127,6 +127,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
Expand Down

0 comments on commit 581b2b6

Please sign in to comment.