Skip to content

Instantly share code, notes, and snippets.

@bhuga
Forked from dpickett/attribute_filter.rb
Created March 4, 2012 19:55
Show Gist options
  • Save bhuga/1974552 to your computer and use it in GitHub Desktop.
Save bhuga/1974552 to your computer and use it in GitHub Desktop.
attribute filter concept for mass assignment
class User < ActiveRecord::Base
protection_strategy :whitelist do
only :first_name, :last_name, :login, :password, :password_confirmation
end
protection_strategy :blacklist do
except :encrypted_password
end
end
u = User.new({protected_attribute: "blah", first_name: "John"}, filter: :whitelist)
# u.attributes => {first_name: "John"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment