Skip to content

Instantly share code, notes, and snippets.

@dpickett
Created March 4, 2012 18:56
Show Gist options
  • Save dpickett/1974358 to your computer and use it in GitHub Desktop.
Save dpickett/1974358 to your computer and use it in GitHub Desktop.
attribute filter concept for mass assignment
class UserAttributeFilter < AttributeFilter::Filter
strategy :whitelist,
attributes: [:first_name, :last_name, :login, :password, :password_confirmation]
end
u = User.new({protected_attribute: "blah", first_name: "John"}, filter: UserAttributeFilter)
# u.attributes => {first_name: "John"}
@lucashungaro
Copy link

I like it. IMHO, way better than using Controllers for that.

@bhuga
Copy link

bhuga commented Mar 4, 2012

Like the idea, would rather it be in the model. See my fork.

@dpickett
Copy link
Author

dpickett commented Mar 5, 2012

@bhuga I like that DSL a lot - I definitely think we can get there with the current implementation. I'd love both of your feedback @ the earlier library I'm putting together: https://github.com/EnlightSolutions/attribute_filter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment