Created
March 5, 2012 15:42
-
-
Save jashkenas/1978885 to your computer and use it in GitHub Desktop.
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
# Select only a sub-set of passed parameters. Useful for whitelisting | |
# attributes from the params hash before performing a mass-assignment. | |
def pick(hash, *keys) | |
filtered = {} | |
hash.each {|key, value| filtered[key.to_sym] = value if keys.include?(key.to_sym) } | |
filtered | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment