# Rails params parsing bug?

**URL:** <https://www.ruby-forum.com/t/rails-params-parsing-bug/140079>\
**Category:** Rails\
**Created:** [June 10, 2008, 5:38pm UTC](https://www.ruby-forum.com/t/rails-params-parsing-bug/140079 "2008-06-10T17:38:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_LIn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Eric\_LIn](https://www.ruby-forum.com/u/Eric_LIn)\
**Post date:** [June 10, 2008, 5:38pm UTC](https://www.ruby-forum.com/t/rails-params-parsing-bug/140079/1 "2008-06-10T17:38:49Z")

</div>

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:

 Gift Miscellaneous Gift Miscellaneous

Thanks,  
Eric

---

<div class="post-metadata">

**Author:** ![Eric\_LIn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Eric\_LIn](https://www.ruby-forum.com/u/Eric_LIn)\
**Post date:** [June 10, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/rails-params-parsing-bug/140079/2 "2008-06-10T18:06:29Z")

</div>

What is the ruby code that generates the HTML?

---

<div class="post-metadata">

**Author:** ![Eric\_LIn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Eric\_LIn](https://www.ruby-forum.com/u/Eric_LIn)\
**Post date:** [June 11, 2008, 12:44am UTC](https://www.ruby-forum.com/t/rails-params-parsing-bug/140079/3 "2008-06-11T00:44:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eric\_LIn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Eric\_LIn](https://www.ruby-forum.com/u/Eric_LIn)\
**Post date:** [June 11, 2008, 12:47am UTC](https://www.ruby-forum.com/t/rails-params-parsing-bug/140079/4 "2008-06-11T00:47:12Z")

</div>

what are you trying to do?

---

<div class="post-metadata">

**Author:** ![Eric\_LIn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Eric\_LIn](https://www.ruby-forum.com/u/Eric_LIn)\
**Post date:** [June 12, 2008, 5:39pm UTC](https://www.ruby-forum.com/t/rails-params-parsing-bug/140079/5 "2008-06-12T17:39:07Z")

</div>

> what are you trying to do?

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

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

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

---

<div class="post-metadata">

**Author:** ![Eric\_LIn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Eric\_LIn](https://www.ruby-forum.com/u/Eric_LIn)\
**Post date:** [June 12, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/rails-params-parsing-bug/140079/6 "2008-06-12T18:54:21Z")

</div>

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](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
