Rails params parsing bug?

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

What is the ruby code that generates the HTML?

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"} ]

what are you trying to do?

what are you trying to do?

Basically the same thing as what's done in this RailsCast

The only difference I see is I did not use Rails helpers in my case.

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