Я создаю приложение для рецептов, в котором пользователь может просматривать рецепты, составлять список ингредиентов, получать список покупок и т. Д. И т. Д.
Каждый рецепт состоит из шагов, каждый шаг имеет ингредиенты, а каждый ингредиентпродуктовый магазин.
Я был совершенно уверен, что способ создания этих ссылок был через модели, поэтому мои модели выглядят так:
class Recipe < ActiveRecord::Base
has_many :steps, :dependent => :destroy
has_many :ingredients, :through => :steps
has_many :groceries, :through => :ingredients
end
class Step < ActiveRecord::Base
belongs_to :recipe
has_many :ingredients, :dependent => :destroy
has_many :groceries, :through => :ingredients
accepts_nested_attributes_for :ingredients
end
class Ingredient < ActiveRecord::Base
belongs_to :step
belongs_to :recipe
has_one :grocery
end
class Grocery < ActiveRecord::Base
has_and_belongs_to_many :ingredients
has_and_belongs_to_many :steps, :through => :ingredients
has_and_belongs_to_many :recipes, :through => :ingredients
end
Я могу вывести debug @ recipe.steps, @recipe.ingredients, но @ recipe.groceries возвращает
uninitialized constant Recipe::Grocery
Я думаю, что это проблема с объединениями, но я не понимаю, почему мне нужно указать соединение в контроллере.
Контроллер просто
def show
@recipe = Recipe.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @recipe }
end
end
Я ищу свою ошибку в нужном месте?или я неверно истолковал ошибку ??