assign_nested_attributes_for_collection_association
- 1.0.0
- 1.1.0
- 1.1.1
- 1.1.6
- 1.2.0
- 1.2.6
- 2.0.0
- 2.0.1
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.2 (0)
- 2.3.8 (2)
- 3.0.0 (-1)
- 3.0.5 (0)
- 3.0.7 (0)
- 3.0.9 (-38)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.3 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- What's this?
assign_nested_attributes_for_collection_association(association_name, attributes_collection, allow_destroy)
private
Assigns the given attributes to the collection association.
Hashes with an :id value matching an existing associated record will update that record. Hashes without an :id value will build a new record for the association. Hashes with a matching :id value and a :_delete key set to a truthy value will mark the matched record for destruction.
For example:
assign_nested_attributes_for_collection_association(:people, { '1' => { :id => '1', :name => 'Peter' }, '2' => { :name => 'John' }, '3' => { :id => '2', :_delete => true } })
Will update the name of the Person with ID 1, build a new associated person with the name `John’, and mark the associatied Person with ID 2 for destruction.
Also accepts an Array of attribute hashes:
assign_nested_attributes_for_collection_association(:people, [ { :id => '1', :name => 'Peter' }, { :name => 'John' }, { :id => '2', :_delete => true } ])


