Skip to content

Instantly share code, notes, and snippets.

@trevorturk
Created October 5, 2008 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorturk/14948 to your computer and use it in GitHub Desktop.
Save trevorturk/14948 to your computer and use it in GitHub Desktop.
# config/initializers/log_protected_attribute_removal.rb
# raises an exception in test environment when trying to mass assign protected attributes
# detail: http://railspikes.com/2008/9/22/is-your-rails-application-safe-from-mass-assignment
if RAILS_ENV == 'test'
ActiveRecord::Base.class_eval do
def log_protected_attribute_removal(*attributes)
raise "Can't mass-assign these protected attributes: #{attributes.join(', ')}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment