This project is archived and is in readonly mode.

#1615 ✓duplicate
Marnen Laibow-Koser

Nested form params do not work reliably

Reported by Marnen Laibow-Koser | December 22nd, 2008 @ 09:12 PM | in 2.x

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!

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages