From: Brian Candler Date: 2009-06-04T23:11:55+09:00 Subject: Re: Nested HTTP params on ruby HTTP requests Dave Garcia wrote: > { :a => :b} => "a=b" > > When the values are arrays it works fine too > > { :a => [:b,:c,:d]} => "a[]=b&a[]=c&a[]=d" > > But when values are hashes serialization doesn't work as expected. > > For example > { :a => [{:b => :c}, {:d => :e}]} => "a[][b]=c&a[][d]=e" Well, firstly, you didn't say what framework is parsing this form data. But also, in this example you're doing mixtures of arrays and hashes, and I don't think that's likely to work. (Of course, feel free to make a patch for whatever framework you're using, and submit it) I think you'll have more luck with hashes of hashes: a[b][c]=d&a[b][d]=e will probably be deserialised as {'a'=>{'b'=>{'c'=>'d','e'=>'f'}}} At least, I'm reasonably sure Rails can handle this. Rack had some issues with its parsing of nested form-data parameters which may or may not have been fixed yet. And if you're using some other framework with its own parameter parsing, then you'll need to look at that separately. > I don't know if there's any other way to do it but browsing the code it > seems that only one nesting level is supported (maybe is an issue on my > ruby version 1.8.6). It's unlikely to be anything to do with your ruby version, unless the deserialisation is being done by some code which is bundled with ruby (the CGI library??) -- Posted via http://www.ruby-forum.com/.