0

I have a recipe, ingredient, Ingredient_Recipe models

recipe has

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

ingredient has

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

Ingredient_Recipe has

belongs_to :recipes
belongs_to :ingredients

in my ui this doenst work anymore

<% @recipe.ingredients.each do |ingredient| %>

EDIT

  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 に答える