Skip to content

Instantly share code, notes, and snippets.

@davepeck
Created February 17, 2011 21:33
Show Gist options
  • Save davepeck/832754 to your computer and use it in GitHub Desktop.
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
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