aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-09-08 09:45:26 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-09-08 09:45:26 -0700
commit4f6875296f6e6ea123130582923284bfd24cd7f1 (patch)
treea9a2964bf08f5958165f45faac245ed1001ff0f9 /activerecord/lib
parent7e6cda15f8dae517f9605f73aa1c966a29d4930a (diff)
downloadrails-4f6875296f6e6ea123130582923284bfd24cd7f1.tar.gz
rails-4f6875296f6e6ea123130582923284bfd24cd7f1.tar.bz2
rails-4f6875296f6e6ea123130582923284bfd24cd7f1.zip
Revert "Revert "Raise UnknownAttributeError when unknown attributes are supplied via mass assignment""
This reverts commit 41efd73887c00ffd228b05d9346ec47a1f3759b9.
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/base.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index bca2db70f8..907495a416 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -122,6 +122,10 @@ module ActiveRecord #:nodoc:
class MissingAttributeError < NoMethodError
end
+ # Raised when unknown attributes are supplied via mass assignment.
+ class UnknownAttributeError < NoMethodError
+ end
+
# Raised when an error occurred while doing a mass assignment to an attribute through the
# <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
# offending attribute.
@@ -2437,7 +2441,11 @@ module ActiveRecord #:nodoc:
attributes = remove_attributes_protected_from_mass_assignment(attributes) if guard_protected_attributes
attributes.each do |k, v|
- k.include?("(") ? multi_parameter_attributes << [ k, v ] : send(k + "=", v)
+ if k.include?("(")
+ multi_parameter_attributes << [ k, v ]
+ else
+ respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}")
+ end
end
assign_multiparameter_attributes(multi_parameter_attributes)