I have a form that sends the following query string to my Rails controller: transaxion[category_association_attributes][][category_id]=2& transaxion[category_association_attributes][][amount]=12& transaxion[category_association_attributes][][category_id]=1& transaxion[category_association_attributes][][amount]=8 But ActionController parses it as: category_association_attributes" => [ {"category_id"=>"2"}, {"category_id"=>"1", "amount"=>"12"}, {"amount"=>"8"} ] Is this a bug? For more information, the HTML form that generated this query string was: <select name="transaxion[category_association_attributes][] [category_id]"> <option value="2" selected>Gift</option> <option value="1">Miscellaneous</option> </select> <input type="text" name="transaxion[category_association_attributes][][amount]" value="12"/> <select name="transaxion[category_association_attributes][] [category_id]"> <option value="2">Gift</option> <option value="1" selected>Miscellaneous</option> </select> <input type="text" name="transaxion[category_association_attributes][][amount]" value="8"/> Thanks, Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What is the ruby code that generates the HTML? On Jun 10, 9:38 am, Eric LIn <ericlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a form that sends the following query string to my Rails > controller: > > transaxion[category_association_attributes][][category_id]=2& > transaxion[category_association_attributes][][amount]=12& > transaxion[category_association_attributes][][category_id]=1& > transaxion[category_association_attributes][][amount]=8 > > But ActionController parses it as: > > category_association_attributes" => > [ {"category_id"=>"2"}, > {"category_id"=>"1", "amount"=>"12"}, > {"amount"=>"8"} ] > > Is this a bug? > > For more information, the HTML form that generated this query string > was: > > <select name="transaxion[category_association_attributes][] > [category_id]"> > <option value="2" selected>Gift</option> > <option value="1">Miscellaneous</option> > </select> > <input type="text" > name="transaxion[category_association_attributes][][amount]" > value="12"/> > > <select name="transaxion[category_association_attributes][] > [category_id]"> > <option value="2">Gift</option> > <option value="1" selected>Miscellaneous</option> > </select> > <input type="text" > name="transaxion[category_association_attributes][][amount]" > value="8"/> > > Thanks, > Eric--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Basically the same as the HTML I posted before. I didn''t use form_for in this case, and just wrote everything by hand. In case you are wondering, I expected the parse result to be: category_association_attributes" => [ {"category_id"=>"2", "amount"=>"12"}, {"category_id"=>"1", "amount"=>"8"} ] On Jun 10, 9:05 am, silkcom <joseph.countm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What is the ruby code that generates the HTML? > > On Jun 10, 9:38 am, Eric LIn <ericlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a form that sends the following query string to my Rails > > controller: > > > transaxion[category_association_attributes][][category_id]=2& > > transaxion[category_association_attributes][][amount]=12& > > transaxion[category_association_attributes][][category_id]=1& > > transaxion[category_association_attributes][][amount]=8 > > > But ActionController parses it as: > > > category_association_attributes" => > > [ {"category_id"=>"2"}, > > {"category_id"=>"1", "amount"=>"12"}, > > {"amount"=>"8"} ] > > > Is this a bug? > > > For more information, the HTML form that generated this query string > > was: > > > <select name="transaxion[category_association_attributes][] > > [category_id]"> > > <option value="2" selected>Gift</option> > > <option value="1">Miscellaneous</option> > > </select> > > <input type="text" > > name="transaxion[category_association_attributes][][amount]" > > value="12"/> > > > <select name="transaxion[category_association_attributes][] > > [category_id]"> > > <option value="2">Gift</option> > > <option value="1" selected>Miscellaneous</option> > > </select> > > <input type="text" > > name="transaxion[category_association_attributes][][amount]" > > value="8"/> > > > Thanks, > > Eric--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ESPNDev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-10 22:47 UTC
Re: Rails params parsing bug?
what are you trying to do? On Jun 10, 8:38 am, Eric LIn <ericlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a form that sends the following query string to my Rails > controller: > > transaxion[category_association_attributes][][category_id]=2& > transaxion[category_association_attributes][][amount]=12& > transaxion[category_association_attributes][][category_id]=1& > transaxion[category_association_attributes][][amount]=8 > > But ActionController parses it as: > > category_association_attributes" => > [ {"category_id"=>"2"}, > {"category_id"=>"1", "amount"=>"12"}, > {"amount"=>"8"} ] > > Is this a bug? > > For more information, the HTML form that generated this query string > was: > > <select name="transaxion[category_association_attributes][] > [category_id]"> > <option value="2" selected>Gift</option> > <option value="1">Miscellaneous</option> > </select> > <input type="text" > name="transaxion[category_association_attributes][][amount]" > value="12"/> > > <select name="transaxion[category_association_attributes][] > [category_id]"> > <option value="2">Gift</option> > <option value="1" selected>Miscellaneous</option> > </select> > <input type="text" > name="transaxion[category_association_attributes][][amount]" > value="8"/> > > Thanks, > Eric--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> what are you trying to do?Basically the same thing as what''s done in this RailsCast http://railscasts.com/episodes/73 The only difference I see is I did not use Rails helpers in my case.> > On Jun 10, 8:38 am, Eric LIn <ericlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a form that sends the following query string to my Rails > > controller: > > > transaxion[category_association_attributes][][category_id]=2& > > transaxion[category_association_attributes][][amount]=12& > > transaxion[category_association_attributes][][category_id]=1& > > transaxion[category_association_attributes][][amount]=8 > > > But ActionController parses it as: > > > category_association_attributes" => > > [ {"category_id"=>"2"}, > > {"category_id"=>"1", "amount"=>"12"}, > > {"amount"=>"8"} ] > > > Is this a bug? > > > For more information, the HTML form that generated this query string > > was: > > > <select name="transaxion[category_association_attributes][] > > [category_id]"> > > <option value="2" selected>Gift</option> > > <option value="1">Miscellaneous</option> > > </select> > > <input type="text" > > name="transaxion[category_association_attributes][][amount]" > > value="12"/> > > > <select name="transaxion[category_association_attributes][] > > [category_id]"> > > <option value="2">Gift</option> > > <option value="1" selected>Miscellaneous</option> > > </select> > > <input type="text" > > name="transaxion[category_association_attributes][][amount]" > > value="8"/> > > > Thanks, > > Eric--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
After a closer look, this appears to be caused by the way Prototype serializes form when remote_form_for is used, as described on this ticket: http://dev.rubyonrails.org/ticket/10101 . Namely, instead of this as the POST body: transaxion[category_association_attributes][][category_id]=2& transaxion[category_association_attributes][][amount]=12& transaxion[category_association_attributes][][category_id]=1& transaxion[category_association_attributes][][amount]=8 Prototype outputs this: transaxion[category_association_attributes][][category_id]=2& transaxion[category_association_attributes][][category_id]=1& transaxion[category_association_attributes][][amount]=12& transaxion[category_association_attributes][][amount]=8 Which throws Rails off. When I switched from using remote_form_for to just form_for, the problem is gone. Since the patch has not made to Rails Core yet, I''m just going to manually serialize the form using custom JavaScript for now. I''m surprised not more people have experienced the same problem. Eric On Jun 12, 8:38 am, Eric LIn <ericlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > what are you trying to do? > > Basically the same thing as what''s done in this RailsCasthttp://railscasts.com/episodes/73 > > The only difference I see is I did not use Rails helpers in my case. > > > > > On Jun 10, 8:38 am, Eric LIn <ericlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a form that sends the following query string to my Rails > > > controller: > > > > transaxion[category_association_attributes][][category_id]=2& > > > transaxion[category_association_attributes][][amount]=12& > > > transaxion[category_association_attributes][][category_id]=1& > > > transaxion[category_association_attributes][][amount]=8 > > > > But ActionController parses it as: > > > > category_association_attributes" => > > > [ {"category_id"=>"2"}, > > > {"category_id"=>"1", "amount"=>"12"}, > > > {"amount"=>"8"} ] > > > > Is this a bug? > > > > For more information, the HTML form that generated this query string > > > was: > > > > <select name="transaxion[category_association_attributes][] > > > [category_id]"> > > > <option value="2" selected>Gift</option> > > > <option value="1">Miscellaneous</option> > > > </select> > > > <input type="text" > > > name="transaxion[category_association_attributes][][amount]" > > > value="12"/> > > > > <select name="transaxion[category_association_attributes][] > > > [category_id]"> > > > <option value="2">Gift</option> > > > <option value="1" selected>Miscellaneous</option> > > > </select> > > > <input type="text" > > > name="transaxion[category_association_attributes][][amount]" > > > value="8"/> > > > > Thanks, > > > Eric--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---