Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Nested form params do not work reliably

#1615

Hi. I think I've just run into a bug in Rails involving nested models and forms. Her's a minimal case.

This works:


<% form_for @recipe do |f| %>
   Ingredient name: <input type="text" name="recipe[ingredient_lines][][ingredient][name]"/>
   <%= submit_tag %>
<% end %>

When form is submitted, params includes

"recipe"=>{"ingredient_lines"=>[{"ingredient"=>{"name"=>"sugar"}}]}

as expected.

This does not work:


<% form_for @recipe do |f| %>
   Unit: <input type="text" name="recipe[ingredient_lines][][unit]"/><br/>
   Ingredient name: <input type="text" name="recipe[ingredient_lines][][ingredient][name]"/>
   <%= submit_tag %>
<% end %>

When form is submitted, params should include

"recipe"=>{"ingredient_lines"=>[{"unit" => "cup", "ingredient"=>{"name"=>"sugar"}}]}

but instead includes

"recipe"=>{"ingredient_lines"=>[{"unit" => "cup", "ingredient"=>{}}]}

This occurs in Rails 2.1.2 and 2.2.2. Let me know if you need more information to track this down. Thanks!

Reported by Marnen Laibow-Koser · December 22nd, 2008 @ 09:12 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none