Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

assign_nested_attributes_for_collection_association should work with …

…Ruby 1.9 [Closes #2106]

Children attributes can be either String's or Symbol's, so let's check if the object responds to to_i.
  • Loading branch information...
commit 8bc314b3b7dca6d3c796760ace1bb9c1d4cadf53 1 parent d8736b2
@franckverrot franckverrot authored tenderlove committed
View
2  activerecord/lib/active_record/nested_attributes.rb
@@ -383,7 +383,7 @@ def assign_nested_attributes_for_collection_association(association_name, attrib
attributes_collection = if keys.include?('id') || keys.include?(:id)
Array.wrap(attributes_collection)
else
- attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes }
+ attributes_collection.sort_by { |i, _| i.respond_to?(:to_i) ? i.to_i : i.object_id }.map { |_, attributes| attributes }
end
end
View
5 activerecord/test/cases/nested_attributes_test.rb
@@ -755,6 +755,11 @@ def test_validate_presence_of_parent_fails_without_inverse_of
Interest.reflect_on_association(:man).options[:inverse_of] = :interests
end
+ def test_can_use_symbols_as_object_identifier
+ @pirate.attributes = { :parrots_attributes => { :foo => { :name => 'Lovely Day' }, :bar => { :name => 'Blown Away' } } }
+ assert_nothing_raised(NoMethodError) { @pirate.save! }
+ end
+
private
def association_setter
Please sign in to comment.
Something went wrong with that request. Please try again.