aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/forbidden_attributes_protection.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2012-09-18 12:33:13 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2012-09-18 12:33:13 -0700
commitc49d959e9d40101f1712a452004695f4ce27d84c (patch)
treef87077668c14ed414e3d819212b0813e74551c8f /activemodel/lib/active_model/forbidden_attributes_protection.rb
parentade701045f0f80399d99151e5583d4f86c68678e (diff)
parent3919fcd61ef999aab9397332ce3017870b184766 (diff)
downloadrails-c49d959e9d40101f1712a452004695f4ce27d84c.tar.gz
rails-c49d959e9d40101f1712a452004695f4ce27d84c.tar.bz2
rails-c49d959e9d40101f1712a452004695f4ce27d84c.zip
Merge pull request #7251 from rails/integrate-strong_parameters
Integrate strong_parameters in Rails 4
Diffstat (limited to 'activemodel/lib/active_model/forbidden_attributes_protection.rb')
-rw-r--r--activemodel/lib/active_model/forbidden_attributes_protection.rb14
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