how to convert a Hash to a URL parameter string??? (i.e. ready for incorporating in a URI to be post'ed)


I’ve been trying to find out if there is already a Rails or Ruby method to convert a Hash to a URL parameter string? Does one exist?

from { “controller”=>“donate”, “amt”=>"
400.00" }
to controller=donate&amt=400.00

i.e. ready to be appended to the end of a URI for a HTTP POST request


Just add them into the options for the url_for and you should be in business. No need to do the conversion first. However, looking at your example. It seems like donate should be a method of a controller and not the controller itself. You’d probably be better off with a Contributions controller [which could provide an index of people who have donated previously as well as other methods] and just using a CRUDdy new/create kind of methodology. At any rate, adding :amt => "
400.00" to the options parameter in url_for will place amt as a parameter in the url.


My scenario was actually a manual HTTP request (see below). I was interested in whether there is an existing ruby or rails method to convert the hash to a string (in the form of a URL parameter string)? I know I can do this manually in ruby quite readily, but just very curious to know whether there is a method already there to do it in one hit?

postData = {"cc"=>"USD", "st"=>"Completed" }   #<=== Doesn't seem to work, needs to be a string
responseString = ""

(, uri.port) do |request|
responseString =, postData).body