Forum: Ruby on Rails how to convert a Hash to a URL parameter string??? (i.e. rea

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2007-02-10 12:46
(Received via mailing list)
Hi,

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?

e.g.
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

Thanks
Greg
70225136eacd3d870f64e03bff678655?d=identicon&s=25 Russell Norris (Guest)
on 2007-02-10 15:21
(Received via mailing list)
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.

RSL
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2007-02-10 20:47
(Received via mailing list)
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 = ""
    Net::HTTP.start(uri.host, uri.port) do |request|
        responseString = request.post(uri.path, postData).body
    end

Greg
This topic is locked and can not be replied to.