Created
July 13, 2011 14:29
-
-
Save tjmcewan/1080395 to your computer and use it in GitHub Desktop.
raise exception on attempted mass assignment of a protected attribute
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
# monkey-patch to raise an exception when attempting to mass-assign a protected attr | |
# more info: http://is.gd/MiA1mn | |
module ActiveModel | |
module MassAssignmentSecurity | |
module Sanitizer | |
protected | |
def warn!(attrs) | |
self.logger.debug "WARNING: Can't mass-assign protected attributes: #{attrs.join(', ')}" if self.logger | |
raise RuntimeError, "these attributes are protected from mass assignment, use `attr_accessible :#{attrs.join(', :')}`" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it'd be great to also add in the name of failing class. wasn't immediately obvious to me so I left it. suggestions welcomed. :-)