Skip to content

Instantly share code, notes, and snippets.

@jmazzi
Created August 28, 2013 21:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmazzi/6371253 to your computer and use it in GitHub Desktop.
Save jmazzi/6371253 to your computer and use it in GitHub Desktop.
Filter arbitrary hashes in rails using your configured filter parameters.
def scrub(hash)
filter_with = Rails.application.config.filter_parameters
ActionDispatch::Http::ParameterFilter.new(filter_with).filter(hash)
end
@jmazzi
Copy link
Author

jmazzi commented Aug 28, 2013

irb(main):022:0> scrub({password: 'testing', email: 'user@gmail.com'})
=> {:password=>"[FILTERED]", :email=>"user@gmail.com"}

irb(main):023:0> scrub({nested: {password: 'testing', email: 'user@gmail.com'} })
=> {:nested=>{:password=>"[FILTERED]", :email=>"user@gmail.com"}}

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