A fairly common UI requirement is for a user to be able to choose an
existing object or create a new one, e.g. select or supply an address
for a shipment. The accepts_nested_attributes_for code goes some way
towards supporting this use case, but falls short in a couple of
areas. The basic problem is that the parameters hash might include
both an 'address_id' value (from a select box of existing addresses
from which to choose) and an 'address_attributes' value (from the
embedded model form), and the behavior of
accepts_nested_attributes_for in this situation is not well-defined
and is in some cases sensitive to the order in which the hash keys are
processed.

I've written up a simple rails app with a unit test suite which
defines the current behavior and exposes at least a few oddities
therein:

http://github.com/dball/nested_test/tree/master

There are probably some other corner cases I failed to consider in
this test suite, but it's at least a start.

I am working around the problem at least partially in my controllers
by massaging the parameters before sending them to the model, but a
more general solution is probably worthwhile. I figured I'd check here
to see if others agree before digging in and trying to patch
active_record itself.

- donald

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to