From 108db00aa90fe266564483ab301cf0669cae600f Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 31 Jul 2008 15:56:46 +0100 Subject: Raise UnknownAttributeError when unknown attributes are supplied via mass assignment --- activerecord/lib/active_record/base.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/base.rb') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 9cb64223e2..29c2995334 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 # attributes= method. The exception has an +attribute+ property that is the name of the # offending attribute. @@ -2400,7 +2404,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) -- cgit v1.2.3 From 656f0e7c6c9a305abaf9f9b7fb80479b6f94efce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Thu, 31 Jul 2008 16:36:23 -0500 Subject: Fix file permissions Signed-off-by: Joshua Peek --- activerecord/lib/active_record/base.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 activerecord/lib/active_record/base.rb (limited to 'activerecord/lib/active_record/base.rb') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb old mode 100755 new mode 100644 -- cgit v1.2.3