Rails params hash unpacking

I am doing an http get using the url
http://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.

On Feb 14, 3:14am, Vasu [email protected] wrote:

[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

That works!! Thanks a lot, Fred.

On Feb 14, 4:57am, Frederick C. [email protected]