sasa555-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-14 11:13 UTC
Prototype 1.6.0.1: reordering of ajax request params
Hello, I''m using Ajax.Request to post array of structures from the client to the Rails server app. Simplified version of the request is as follows: new Ajax.Request(''www.somesite.com'', { parameters: ''object_array[][field]=1&object_array[][other_field]=2&object_array[] [field]=3&object_array[][other_field]=4'' } ) This works fine with prototype 1.5.1, and rails can recognize this as nested structure: params["object_array"] will be [{"field" => "1", "other_field" => "2"}, {"field" => "3", "other_field" => "4"}] However, with the new Prototype version, when I invoke the code above, the parameters string gets miraculously transformed into: object_array[][field]=1&object_array[][field]=3&object_array[] [other_field]=2&object_array[][other_field]=4 Notice how reordering happened, and how the two values of ''field'' are first provided, followed by the values of ''other_field''. This in turn breakes the behavior in Rails where: params["object_array"] will be [{"field" => "1"}, {"field" => "3", "other_field" => 2}, {"other_field" => "3"}] Anybody has the idea why does this reordering occur, and what could I do about it? Obviously, I could send two arrays instead of one 2D array, but I''d like to avoid it if possible. Thanks in advance! Regards, Sasa --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I have opened a ticket for this problem: http://dev.rubyonrails.org/ticket/8775 and there is another discussing the problem from the controller perspective: http://dev.rubyonrails.org/ticket/9030 and lastobelus posted a path that corrects the problem on the controller side: http://dev.rubyonrails.org/ticket/10101 Hope it helps. Okada. On Dec 14, 9:13 am, "sasa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <sasa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I''m using Ajax.Request to post array of structures from the client to > the Rails server app. > Simplified version of the request is as follows: > > new Ajax.Request(''www.somesite.com'', { > parameters: > ''object_array[][field]=1&object_array[][other_field]=2&object_array[] > [field]=3&object_array[][other_field]=4'' > } > ) > > This works fine with prototype 1.5.1, and rails can recognize this as > nested structure: > params["object_array"] will be > [{"field" => "1", "other_field" => "2"}, {"field" => "3", > "other_field" => "4"}] > > However, with the new Prototype version, when I invoke the code above, > the parameters string gets miraculously transformed into: > object_array[][field]=1&object_array[][field]=3&object_array[] > [other_field]=2&object_array[][other_field]=4 > > Notice how reordering happened, and how the two values of ''field'' are > first provided, followed by the values of ''other_field''. > > This in turn breakes the behavior in Rails where: > params["object_array"] will be > [{"field" => "1"}, {"field" => "3", "other_field" => 2}, > {"other_field" => "3"}] > > Anybody has the idea why does this reordering occur, and what could I > do about it? > Obviously, I could send two arrays instead of one 2D array, but I''d > like to avoid it if possible. > > Thanks in advance! > > Regards, > Sasa--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---