0

我有一个食谱、成分、成分_食谱模型

食谱有

has_many :ingredient_recipes
has_many :Ingredients, :through => :RecipeIngredient

成分有

has_many :ingredient_recipes
has_many :Recipes, :through => :RecipeIngredient 

成分_配方有

belongs_to :recipes
belongs_to :ingredients

在我的用户界面中,这不再起作用

<% @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 >
4

1 回答 1

1

改变:

has_many :Ingredients, :through => :RecipeIngredient

has_many :ingredients, :through => :ingredient_recipes

不要大写 :ingredients ,并且 :through 需要引用您正在经历的关联而不是模型。

对于:食谱:

has_many :recipes, :through => :ingredient_recipes 
于 2012-06-09T13:11:26.810 回答