Skip to content

Instantly share code, notes, and snippets.

@dgmike
Created October 10, 2014 13:59
Show Gist options
  • Save dgmike/3b814e87237a14085aaf to your computer and use it in GitHub Desktop.
Save dgmike/3b814e87237a14085aaf to your computer and use it in GitHub Desktop.
Convert all params from controller to only digits
# rails
# pre-defined method in string
class String
def digits
self.gsub /\D/, ''
end
end
# in my controller
find_params = params
.permit(:field1, :field2)
.map { |k, v| [k, v.digits] }
.to_h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment