From a8f6d5c6450a7fe058348a7f10a908352bb6c7fc Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Fri, 13 Jul 2012 03:51:13 -0500 Subject: Integrate ActiveModel::ForbiddenAttributesProtection from StrongParameters gem --- activemodel/lib/active_model.rb | 1 + .../lib/active_model/forbidden_attributes_protection.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 activemodel/lib/active_model/forbidden_attributes_protection.rb (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index d1cc19ec6b..f8b2b79906 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -34,6 +34,7 @@ module ActiveModel autoload :Conversion autoload :Dirty autoload :EachValidator, 'active_model/validator' + autoload :ForbiddenAttributesProtection autoload :Lint autoload :MassAssignmentSecurity autoload :Model diff --git a/activemodel/lib/active_model/forbidden_attributes_protection.rb b/activemodel/lib/active_model/forbidden_attributes_protection.rb new file mode 100644 index 0000000000..39f1a20734 --- /dev/null +++ b/activemodel/lib/active_model/forbidden_attributes_protection.rb @@ -0,0 +1,14 @@ +module ActiveModel + class ForbiddenAttributes < StandardError + end + + module ForbiddenAttributesProtection + def sanitize_for_mass_assignment(new_attributes, options = {}) + if !new_attributes.respond_to?(:permitted?) || (new_attributes.respond_to?(:permitted?) && new_attributes.permitted?) + super + else + raise ActiveModel::ForbiddenAttributes + end + end + end +end -- cgit v1.2.3