This project is archived and is in readonly mode.
fields_for with nested attributes association should accept explicitly passed objects
Reported by Pascal Ehlert | February 2nd, 2009 @ 09:59 PM | in 2.x
Currently when you pass an explicit object to nested attributes' fields_for helper, it will simply be ignored.
This patch yields it as the builder's object in the block.
One could argue whether this is actually needed or not (you can use build outside of the template after all), but for compatibility with the existing fields_for it does make sense to me. Should be a no-brainer.
Comments and changes to this ticket
-
Pascal Ehlert February 2nd, 2009 @ 10:09 PM
Should have mentioned that this only applies for one-to-one associations..
-
Michael Koziarski February 3rd, 2009 @ 05:50 AM
Wouldn't this only work with ActiveRecord objects? Not sure if that's a deal breaker here, but seems like we should be able to work with it another way.
-
Pascal Ehlert February 3rd, 2009 @ 05:59 AM
That's true, it works for all objects that respond to "new_record?"..
You may have noticed that I've been inspired by the existing code here which is why I thought it would be a reasonable assumption.
I didn't like this too much myself, but I think in order to work with form helpers, attributes should have a #new_record? method anyway.
Maybe we can just put a note somewhere in the rdoc of form_for?
-
Eloy Duran February 3rd, 2009 @ 09:50 AM
@Michael: Well ActiveRecord and DataMapper and any objecty which responds to new_record?. (The same kind of stuff happens on line 261 btw.)
It's not a deal breaker though, we need an ID for new records as well. So since we are already assuming the new_record? method, I chose to use that to check if an object is a record or not.
-
Repository February 6th, 2009 @ 12:48 AM
- State changed from new to committed
(from [d15d53cf810014b90827015ecd0e601176492fb7]) Allowing an object to be passed explicitly to a fields_for with nested_attributes on one-to-one associations
Signed-off-by: Michael Koziarski michael@koziarski.com [#1849 state:committed] http://github.com/rails/rails/co...
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>
People watching this ticket
Attachments
Tags
Referenced by
- 1849 fields_for with nested attributes association should accept explicitly passed objects Signed-off-by: Michael Koziarski michael@koziarski.com [#...