Greg Hauptmann
2007-Feb-10 11:45 UTC
how to convert a Hash to a URL parameter string??? (i.e. ready for incorporating in a URI to be post''ed)
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Feb-10 14:20 UTC
Re: how to convert a Hash to a URL parameter string??? (i.e. ready for incorporating in a URI to be post''ed)
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 On 2/10/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-10 19:46 UTC
Re: how to convert a Hash to a URL parameter string??? (i.e. ready for incorporating in a URI to be post''ed)
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
On 2/11/07, Russell Norris
<sconds-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> 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
>
> On 2/10/07, Greg Hauptmann <
greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> >
> > 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
> >
> >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---