You have
/recipe/:recipe_id/ingredient/:ingredient_id/edit
which is a route to edit an existing ingredient. But your form
<%= form_for([@recipe, @recipe.ingredients.build]) do |f| % >
is expecting you to build a new ingredient which belongs to @recipe.
If you want to edit an existing ingredient then you need to get it using your params.
@recipe = Recipe.find params[:recipe_id]
@ingredient = @recipe.ingredients.find params[:ingredient_id]
<%= form_for([@recipe, @ingredient]) do |f| % >
I don't really know what example you're following but I guess an ingredient is a many to many join between recipe and (say) food? If that is the case, and ingredient belongs to a recipe rather than many recipes then you can do this:
/ingredient/:ingredient_id/edit
@ingredient = Ingredient.find params[:ingredient_id]
@recipe = @ingredient.recipe
and thus:
<%= form_for(@ingredient) do |f| % >
further suggestion:
I can't say for sure without seeing all your template but are you doing something like:
<%- form_for @item do |f| -%>
<%= f.fields_for :field -%>
<%- form_for @different_item do |ff| -%>
<%= ff.fields_for :another_field -%>
<%- end -%>
<%- end -%>
Actually, can you post the gist of your form as above.
mark
2010-09-15 21:06:35