Skip to content

Instantly share code, notes, and snippets.

@fadhlirahim
Created October 27, 2011 17:17
Show Gist options
  • Save fadhlirahim/1320181 to your computer and use it in GitHub Desktop.
Save fadhlirahim/1320181 to your computer and use it in GitHub Desktop.
Filter params allowed to go thru
# Make sure that we don't allow attributes to be mass assigned from Backbone saves
# http://www.quora.com/Backbone-js-1/How-well-does-backbone-js-work-with-rails
# Always whitelist and validate your incoming attributes.
#
# Usage
#
# model.update_attributes pick(params, :title, :description)
#
def pick(hash, *keys)
filtered = {}
hash.each do |key, value|
filtered[key.to_sym] = value if keys.include?(key.to_sym)
end
filtered
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment