# Complex Forms Misbehavior (possibly a Rails bug)

**URL:** <https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168>\
**Category:** Rails\
**Created:** [December 26, 2007, 12:21am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168 "2007-12-26T00:21:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 26, 2007, 12:21am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/1 "2007-12-26T00:21:57Z")

</div>

Hi Leuddens

This is a tricky and lengthy one that’s about to blow my current project  
to little glittering pieces 😉

I’m using select multiple in a subform (as described in Ryan’s excellent  
Complex Forms screencasts on [railscasts.com](http://railscasts.com). This is the relation:

Offer has\_and\_belongs\_to\_many :parts  
Part has\_many :manufacturers

The Offer form allows you to add/remove parts. And the \_part.html.erb  
partial contains one text\_input “name” and one select-multiple  
“manufacturer\_ids”.

The object (form element) names in the \_part partial are correctly named  
“offer[part\_attributes][]” and the select multiple adds  
“[manufacturer\_ids][]” to it, which results in the nice to look at…

offer[part\_attributes][][manufacturer\_ids][]

I create two parts and select two manufacturers for each part, hit  
submit and take a look at the params hash:

[  
{“manufacturer\_ids”=\>[], “name”=\>“FIRST PART”},  
{“manufacturer\_ids”=\>[]},  
{“manufacturer\_ids”=\>[], “name”=\>“SECOND PART”},  
{“manufacturer\_ids”=\>[]},  
{“manufacturer\_ids”=\>[]},  
{“manufacturer\_ids”=\>[]}  
]

That doesn’t look too good. Apparently, the form parameters are not  
parsed correctly into the params hash at all.

After some research, I found the follwing patch:  
[http://dev.rubyonrails.org/ticket/10101](http://dev.rubyonrails.org/ticket/10101)

Once applied, the output looks slightly better:

params[:offer][:part\_attributes] =\>  
[  
{“manufacturer\_ids”=\>[“209”], “name”=\>“FIRST PART”},  
{“manufacturer\_ids”=\>[“254”], “name”=\>“SECOND PART”},  
{“manufacturer\_ids”=\>[“238”]},  
{“manufacturer\_ids”=\>[“209”]},  
{“manufacturer\_ids”=\>[“254”]},  
{“manufacturer\_ids”=\>[“238”]}  
]

But this is still not what ActiveRecord needs in order to write the  
records correctly. Even worse: The nesting (which manufacturer\_ids  
belong to which part) are lost, so I can’t even tweak the params hash  
manually in the controller.

I can’t believe that I’m the only one facing this issue. As a matter of  
fact, if you decide to have a another complex form within yet a complex  
form partial, you will face the same challenge.

Unfortunately, the UrlEncodedPairParser - that seems responsible for  
this - is too magic for my skills.

Please help, somebody, I’m really stuck knee deep with this one.

Many thanks! -sven

PS:  
Could Ruby 1.8’s Array handling (random member order) have anything to  
do with this? If so, Ruby 1.9 might help as it maintains Array member  
order - unfortunately, I have no install of Ruby 1.9 at hand to verify  
this.

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 26, 2007, 1:50am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/2 "2007-12-26T01:50:54Z")

</div>

On Dec 25, 3:21 pm, Sven S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Could Ruby 1.8’s Array handling (random member order) have anything to  
> do with this? If so, Ruby 1.9 might help as it maintains Array member  
> order - unfortunately, I have no install of Ruby 1.9 at hand to verify  
> this.

Rails isn’t yet comptatible with Ruby 1.9, in my understanding.

///ark

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 26, 2007, 3:14am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/3 "2007-12-26T03:14:34Z")

</div>

Mark W. wrote:

> On Dec 25, 3:21ï¿½pm, Sven S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Could Ruby 1.8’s Array handling (random member order) have anything to  
> > do with this? If so, Ruby 1.9 might help as it maintains Array member  
> > order - unfortunately, I have no install of Ruby 1.9 at hand to verify  
> > this.
> 
> Rails isn’t yet comptatible with Ruby 1.9, in my understanding.
> 
> ///ark

is ruby 1.9 out yet?

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 26, 2007, 6:15am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/4 "2007-12-26T06:15:13Z")

</div>

On Dec 25, 8:14 pm, Xk Lin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> is ruby 1.9 out yet?

It was released today (Christmas Day).

```
http://www.ruby-lang.org/en/news/

```

However, it is a development release only, so it may not be completely  
stable. The know stable version is on the download page and is 1.8.6-  
p111.

–  
Travis

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 26, 2007, 6:17am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/5 "2007-12-26T06:17:33Z")

</div>

On Dec 25, 6:50 pm, Mark W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Rails isn’t yet comptatible with Ruby 1.9, in my understanding.

Ruby 1.9 on Rails 2.0 tests correctly for me. However, Ruby 1.9 on  
Rails 1.2 may not.

Also, remember that the Ruby 1.9, released today, is still a  
development release, so not everything may be working properly with  
the Ruby interpreter.

–  
Travis

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 26, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/6 "2007-12-26T23:08:39Z")

</div>

tekwiz wrote:

> On Dec 25, 6:50 pm, Mark W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Rails isn’t yet comptatible with Ruby 1.9, in my understanding.
> 
> Ruby 1.9 on Rails 2.0 tests correctly for me. However, Ruby 1.9 on  
> Rails 1.2 may not.
> 
> Also, remember that the Ruby 1.9, released today, is still a  
> development release, so not everything may be working properly with  
> the Ruby interpreter.
> 
> –  
> Travis

I’ll give Ruby 1.9 a try as soon as I can.

But I’m not even sure whether it will have an influence on this issue.  
It would be great to get in touch with someone who knows a little  
something about how Rails parses the request into the params hash.

Big thanks!! -sven

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 27, 2007, 12:04am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/7 "2007-12-27T00:04:25Z")

</div>

On 26 Dec 2007, at 05:16, tekwiz wrote:

> On Dec 25, 6:50 pm, Mark W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Rails isn’t yet comptatible with Ruby 1.9, in my understanding.
> 
> Ruby 1.9 on Rails 2.0 tests correctly for me. However, Ruby 1.9 on  
> Rails 1.2 may not.

Have you actually run the rails unit tests? There are still many  
failing tests on 1.9

Fred

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [December 26, 2007, 8:24am UTC](https://www.ruby-forum.com/t/complex-forms-misbehavior-possibly-a-rails-bug/124168/8 "2007-12-26T08:24:19Z")

</div>

On Dec 25, 9:16 pm, tekwiz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ruby 1.9 on Rails 2.0 tests correctly for me. However, Ruby 1.9 on  
> Rails 1.2 may not.

I got my information from  
[http://blog.codefront.net/2007/12/26/ruby-190-has-been-released/](http://blog.codefront.net/2007/12/26/ruby-190-has-been-released/)

///ark
