我有配方,成分,Ingredient_Recipe模型
食谱
has_many :ingredient_recipes
has_many :Ingredients, :through => :RecipeIngredient
成分
has_many :ingredient_recipes
has_many :Recipes, :through => :RecipeIngredient
Ingredient_Recipe有
belongs_to :recipes
belongs_to :ingredients
在我的ui这个最重要的工作
<% @recipe.ingredients.each do |ingredient| %>
编辑
ActionView::Template::Error (uninitialized constant Recipe::Ingredients):
97: </td>
98: <tr>
99: <td >
100: <% @recipe.ingredients.each do |ingredient| %>
101: ingredient.name
102: <% end %>
103: </td >
答案 0 :(得分:1)
变化:
has_many :Ingredients, :through => :RecipeIngredient
到
has_many :ingredients, :through => :ingredient_recipes
不要大写:成分,并且:通过需要引用您正在经历的关联而不是模型。
对于:食谱:
has_many :recipes, :through => :ingredient_recipes