기본적인 요리 책을 만들고 싶습니다. 요리법과 함께 성분 관계.레서피에 수량 추가 habtm 성분 관계
첫 번째 시도는 이와 같았습니다.
class Recipe < ActiveRecord::Base
# title, description
has_many :recipe_ingredients
end
class Ingredient < ActiveRecord::Base
# name, unit
has_many :recipe_ingredients
has_many :recipes, :through => :recipe_ingredients
end
class RecipeIngredient < ActiveRecord::Base
belongs_to :recipe
belongs_to :ingredient
attr_accessible :amount
end
그리고이 추한 느낌 손
RecipeIngredient.create(:recipe_id => 1, :ingredient_id => 2, :amount => 100)
recipe.recipe_ingredients.amout
recipe.recipe_ingredients.ingredient.unit
recipe.recipe_ingredients.ingredient.name
에 의해 관계를 만들었습니다. 그러나 나는 다른 해결책을 모른다.
야호 타이핑 recipes.recipes을 ... 나쁜입니다. 감사 – Henning