Complex Forms Misbehavior (possibly a Rails bug)

Hi Leuddens

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

I’m using select multiple in a subform (as described in Ryan’s excellent
Complex Forms screencasts on 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

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.

On Dec 25, 3:21 pm, Sven S. [email protected]
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

Mark W. wrote:

On Dec 25, 3:21�pm, Sven S. [email protected]
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?

On Dec 25, 8:14 pm, Xk Lin [email protected] 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

On Dec 25, 6:50 pm, Mark W. [email protected] 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

tekwiz wrote:

On Dec 25, 6:50 pm, Mark W. [email protected] 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

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

On Dec 25, 6:50 pm, Mark W. [email protected] 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

On Dec 25, 9:16 pm, tekwiz [email protected] 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/

///ark

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs