不是最好的办法,但我补充说
:recipe_ingredients
将“编辑和创建”路由并移动到
ingredients_controller
添加了这个超级丑陋的path_助手,lol。
resources :users, only: [:new, :create, :show ]
resources :recipes, :recipe_ingredients do
resources :ingredients, only: [:new, :create, :edit, :update]
end
<tbody>
<% @recipe.recipe_ingredients.each do |recipe_ingredient| %>
<tr>
<td><%#= check_box_tag "recipe_ingredient_ids[]", recipe_ingredient.id %> </td>
<td><%= recipe_ingredient.ing_name %></td>
<td><%= recipe_ingredient.amount %> <%= link_to 'Edit Ingredient',
edit_recipe_ingredient_ingredient_path(recipe_ingredient) %> </td>
</tr>
<% end %>
</tbody>
</table>
def update
@recipe = Recipe.find(params[:id])
recipe_ingredient = RecipeIngredient.find(params[:recipe_id])
recipe_ingredient.update(amount: params[:recipe_ingredient][:recipe_ingredients][:amount].to_f)
redirect_to recipe_path(@recipe)
end