diff options
Diffstat (limited to 'activemodel/lib/active_model/forbidden_attributes_protection.rb')
-rw-r--r-- | activemodel/lib/active_model/forbidden_attributes_protection.rb | 14 |
1 files changed, 14 insertions, 0 deletions
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..a5e4c4f650 --- /dev/null +++ b/activemodel/lib/active_model/forbidden_attributes_protection.rb @@ -0,0 +1,14 @@ +module ActiveModel + class ForbiddenAttributesError < StandardError + end + + module ForbiddenAttributesProtection + def sanitize_for_mass_assignment(attributes, options = {}) + if attributes.respond_to?(:permitted?) && !attributes.permitted? + raise ActiveModel::ForbiddenAttributesError + else + attributes + end + end + end +end |