That works!! Thanks a lot, Fred.

On Feb 14, 4:57 am, Frederick Cheung <[email protected]>
wrote:
> On Feb 14, 3:14 am,Vasu<[email protected]> wrote:
>
> > I am doing an http get using the 
> > urlhttp://localhost/add?add_key[0][key]=1234&add_key[0][id]=1.
> > I have a rails app which gives me a neat params hash
> > {"add_key"=>{"0"=>{"key"=>"1234", "id"=>"1"}}.
>
> > Now I try to post these to another server, using Net::HTTP.post_form
> > new_url,params
>
> > The second server gets a form hash -  {"add_key"=>"0key1234id1"}.
> > Looks like post_form requires a string:string hash. How do I unpack
> > the params hash back to the original parameter syntax -  {"add_key[0]
> > [key]" => "1234", add_key[0][id]" => "1"} ?
>
> > I have used CGI.parse which works if the original request is a GET.
> > But if the parameters are passed in a POST, it doesn't work.
>
> Try the .to_query method
>
> 1.9.2p180 :004 > {"add_key"=>{"0"=>{"key"=>"1234",
> "id"=>"1"}}}.to_query
>  => "add_key%5B0%5D%5Bid%5D=1&add_key%5B0%5D%5Bkey%5D=1234"
>
> (%5B and %5D are the encoded versions of [ and ])
>
> Fred

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to