Created
October 10, 2014 13:59
-
-
Save dgmike/3b814e87237a14085aaf to your computer and use it in GitHub Desktop.
Convert all params from controller to only digits
This file contains hidden or 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
# 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