デモアプリのRails3のモデルを使用して、多対多の関係を実装しようとしています。
リレーションに関するデータをもう少し保持するモデルを追加しようとするまで、すべて正常に機能しました。
レシピ、材料、Ingredient_Recipeモデルがあります
ファイル:ingredient_recipe.rb
class IngredientRecipe < ActiveRecord::Base
attr_accessible :created_at, :ingredient_id, :order, :recipe_id
belongs_to :recipes
belongs_to :ingredients
end
ファイル:ingredient.rb
class Ingredient < ActiveRecord::Base
has_many :ingredientRecipe
has_many :recipes, :through => :ingredientRecipe
...
File:recipes.rb
class Recipe < ActiveRecord::Base
has_many :ingredientRecipe
has_many :ingredients, :through => :ingredientRecipe
...
UIで
<td >
<% @recipe.ingredients.each do |ingredient| %>
ingredient.name
<% end %>
</td >
テーブル
ingredient_id, recipe_id, order, created_at, updated_at
さて、これはあまりうまくいきません...
まあ、そして多対多を実装するための良いリソースは非常に高く評価されます