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!