【发布时间】:2017-09-08 01:04:16
【问题描述】:
我有一个Recipe 模型和一个Ingredient 模型。他们都has_many :recipe_ingredients 和配方has_many :ingredients, through: recipe_ingredients 和成分has_many :recipes, through: recipe_ingredients 和RecipeIngredient belongs_to 配方和成分。来自recipe#show 我有一个link_to new_recipe_ingredient_path(@recipe)。在那个观点中,我有
<%= form_for @recipe_ingredient do |f| %>
<%= f.collection_select :ingredient_id, Ingredient.all, :id, :name %>
<%= f.label :amount %>
<%= f.number_field :amount %>
<%+ f.submit %>
<% end %>
我的问题是,我需要在ingredients_controller 中创建RecipeIngredient 表中的记录吗?我试过铲入参数。我已经尝试直接在 INgredient 控制器中创建 RecipeIngredient 并得到一个禁止属性错误。我尝试其他事情并得到类型不匹配。我想知道是否可以重定向到 REcipeINgredient 控制器中的 create 方法并在那里创建它。
【问题讨论】:
标签: ruby-on-rails ruby activerecord