From 9af5867b6faf27c8f1bcda94c3e96e5d9c69263c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 1 Oct 2013 08:17:01 +0200 Subject: [PATCH] Improved error handling. --- app/models/application_model.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 8b8b82018..97743f156 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -89,8 +89,12 @@ returns self.class.reflect_on_all_associations.map { |assoc| real_key = assoc.name.to_s[0,assoc.name.to_s.length-1] + '_ids' if params.has_key?( real_key.to_sym ) + list_of_items = params[ real_key.to_sym ] + if params[ real_key.to_sym ].class != Array + list_of_items = [ params[ real_key.to_sym ] ] + end list = [] - params[ real_key.to_sym ].each {|item| + list_of_items.each {|item| list.push( assoc.klass.find(item) ) } self.send( assoc.name.to_s + '=', list )