Skip to content

Instantly share code, notes, and snippets.

@unnitallman
Created September 28, 2011 12:28
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 unnitallman/1247809 to your computer and use it in GitHub Desktop.
Save unnitallman/1247809 to your computer and use it in GitHub Desktop.
Adding query string to a url
>> callback = Addressable::URI.parse("http://unni.com")
=> #<Addressable::URI:0x810ab0b4 URI:http://unni.com>
>> callback.query_values = callback.query_values ? callback.query_values.merge({"angry" => "birds"}) : {"angry" => "birds"}
=> {"angry"=>"birds"}
>> callback.to_s
=> "http://unni.com?angry=birds"
>> callback = Addressable::URI.parse("http://unni.com?nikhil=krishna")
=> #<Addressable::URI:0x8109fc8c URI:http://unni.com?nikhil=krishna>
>> callback.query_values = callback.query_values ? callback.query_values.merge({"angry" => "birds"}) : {"angry" => "birds"}
=> {"angry"=>"birds", "nikhil"=>"krishna"}
>> callback.to_s
=> "http://unni.com?angry=birds&nikhil=krishna"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment