This project is archived and is in readonly mode.

#5746 ✓resolved
James MacAulay

[PATCH] rendering a partial with an array as its :object should not behave as if it were passed as :collection

Reported by James MacAulay | September 30th, 2010 @ 07:42 PM

This code does not work the same way as it did in 2.x:

render :partial => "things", :object => ['foo', 'bar', 'baz']

In 2.x, the "things" partial would be rendered once with a local variable called "things" storing the given array.

In 3.0.0 (and edge), the Action View assumes that you really meant :collection => ['foo', 'bar', 'baz'], so it iterates through the array and renders the partial once with each element. It will do this for any object which responds to to_ary.

I really think this is a case of Rails being too clever for its own good. The difference in behaviour between the :object and :collection options is large enough that this cleverness makes for a big break in expectations. If someone wants the :collection behaviour, they should use :collection.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments