Created
February 11, 2014 16:01
-
-
Save akiatoji/8937750 to your computer and use it in GitHub Desktop.
How to handle those cases when you just can't deal with how Rails Hash.to_query uses '+' instead of '%20'
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
# Add this to initializers | |
# | |
# { foo: 'real foo' }.to_query => real+foo | |
# { foo: 'real foo' }.to_spacey_query => real%20foo | |
Hash.class_eval do | |
def to_spacey_query | |
collect do |key, value| | |
"#{ key.to_param }=#{ ERB::Util::u(value.to_param.to_s)} " | |
end.sort * '&' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment