Created
March 4, 2012 18:56
-
-
Save dpickett/1974358 to your computer and use it in GitHub Desktop.
attribute filter concept for mass assignment
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
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"} |
Like the idea, would rather it be in the model. See my fork.
@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
I like it. IMHO, way better than using Controllers for that.