Skip to content

Instantly share code, notes, and snippets.

@akiatoji
Created February 11, 2014 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiatoji/8937750 to your computer and use it in GitHub Desktop.
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'
# 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