This project is archived and is in readonly mode.
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
-
Frederick Cheung December 23rd, 2008 @ 11:13 PM
- State changed from new to duplicate
Looks the same as #1622 to me.
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>