Created
August 14, 2012 06:56
-
-
Save lulalala/3347072 to your computer and use it in GitHub Desktop.
How to append a parameter into the url in Ruby?
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
u = URI.parse("http://example.com/user/1234?a=1&b=2") | |
# <URI::HTTP:0x007fe3d9a1f238 URL:http://example.com/user/1234?a=1&b=2> | |
query = u.query #"a=1&b=2" | |
query = query << "&c=3" | |
u.path #"/user/1234" | |
u.to_s #"http://example.com/user/1234?a=1&b=2" | |
u.merge(query).to_s #"http://example.com/user/a=1&b=2&c=3" WHY DOES 1234 disappear?! | |
# I want to get http://example.com/user/1234?a=1&b=2&c=3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment