Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#5746

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.

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

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. James MacAulay
    James MacAulay
    • Title changed from rendering a partial with an array as its :object behaves as if it were :collection to [PATCH] rendering a partial with an array as its :object should not behave as if it were passed as :collection
    • Tag changed from action_view to action_view, bug

    Made a patch to fix this. At first I thought this was an intentional change, but after working with the code more I realize that it's probably just a bug.

    September 30th, 2010 @ 08:28 PM

  2. James MacAulay
  3. Repository
    Repository
    • State changed from new to resolved

    (from [581b2b68368e3330cc725a305d0e2465c2e71e1c]) fix rendering a partial with an array as its :object [#5746 [PATCH] rendering a partial with an array as its :object should not behave as... state:resolved]

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

    Conflicts:

    actionpack/lib/action_view/render/partials.rb
    

    http://github.com/rails/rails/commit/581b2b68368e3330cc725a305d0e24...

    October 7th, 2010 @ 11:12 PM

  4. Repository
  5. Ryan Bigg
    Ryan Bigg
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 11th, 2010 @ 10:54 AM