From e910bece3415b3cfd9f023c1cacd39554f0f1b2a Mon Sep 17 00:00:00 2001 From: Jonathan Barket Date: Fri, 20 Feb 2009 18:04:48 -0600 Subject: [PATCH] Added the ability for habtm mass assignment to also work if a string of ids is passed in the format ["1,2,3,4"] as ExtJS and others do. --- activerecord/lib/active_record/associations.rb | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 05ce8ff..86c341e 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1360,6 +1360,11 @@ module ActiveRecord define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value| ids = (new_value || []).reject { |nid| nid.blank? } + # Check for strings in the format "1,2,3" and convert them + # Useful for nested forms passing multiple param values + if ids.first.kind_of?(String) and ids.first =~ /(\d,)+\d/ + ids = ids[0].split(",").map { |id| id.to_i } + end send("#{reflection.name}=", reflection.class_name.constantize.find(ids)) end end -- 1.6.1.2