From 7f743233c4e276d1799451478e6718589d270cbd Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 26 Sep 2010 00:35:39 -0400 Subject: Fix for nested_attributes with has_many association fails when a single record is being updated. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5705 state:resolved] Signed-off-by: José Valim --- activerecord/lib/active_record/nested_attributes.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/nested_attributes.rb') diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 7372ab3278..bdd940f3ee 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -377,7 +377,12 @@ module ActiveRecord end if attributes_collection.is_a? Hash - attributes_collection = attributes_collection.sort_by { |index, _| index.to_i }.map { |_, attributes| attributes } + keys = attributes_collection.keys + 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 } + end end association = send(association_name) -- cgit v1.2.3