I want to form a url like
http://www.google.com?name=john%20doe
using Ruby.
I have
u = URI::HTTP.build(host: 'www.google.com', query: { name: 'john doe' }.to_query)
u.to_s
gives me http://www.google.com?name=john+doe
.
The whitespace in john doe
is replaced with +
because
{ name: 'john doe' }.to_query
returns name=john+doe
(to_query is a Rails addition I believe)
I want %20
instead of +
. How do I achieve this easily?
I'm aware that URI::encode
does encode a whitespace to a %20
, but I wonder if there's a better way than converting a hash to a string and then sending it through URI::encode.