Created
February 17, 2011 21:33
-
-
Save davepeck/832754 to your computer and use it in GitHub Desktop.
Shove this in your Rails 3 config/initializers/ to raise exceptions on bad mass assignment attempts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless Rails.env.production? | |
module ActiveModel | |
class IllegalMassAssignment < StandardError | |
end | |
module MassAssignmentSecurity | |
module Sanitizer | |
def warn!(invalid_keys) | |
raise ActiveModel::IllegalMassAssignment, "You attempted to mass-assign: #{invalid_keys.join(', ')}" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment