diff options
author | Mike Breen <hardbap@gmail.com> | 2009-07-11 14:30:35 +0200 |
---|---|---|
committer | Eloy Duran <eloy.de.enige@gmail.com> | 2009-09-12 15:37:54 +0200 |
commit | bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4 (patch) | |
tree | 9bce1073883ad4facad446b06f8d2cd53d224358 /activerecord/lib/active_record | |
parent | 3180619c0d228812c119e9704ac5956cbcad8614 (diff) | |
download | rails-bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4.tar.gz rails-bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4.tar.bz2 rails-bcd0ef710ec6d2cc6b880c39de0dfacc07df85e4.zip |
Raise an exception with friendlier error message when attempting to build a polymorphic belongs_to with accepts_nested_attributes_for. [#2318 state:resolved]
Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/nested_attributes.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index bc4cca7855..0def6d5c89 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -260,7 +260,12 @@ module ActiveRecord if attributes['id'].blank? unless reject_new_record?(association_name, attributes) - send("build_#{association_name}", attributes.except(*UNASSIGNABLE_KEYS)) + method = "build_#{association_name}" + if respond_to?(method) + send(method, attributes.except(*UNASSIGNABLE_KEYS)) + else + raise ArgumentError, "Cannot build association #{association_name}. Are you trying to build a polymorphic one-to-one association?" + end end elsif (existing_record = send(association_name)) && existing_record.id.to_s == attributes['id'].to_s assign_to_or_mark_for_destruction(existing_record, attributes, allow_destroy) |