【发布时间】:2011-04-27 06:41:45
【问题描述】:
我正在构建一个食谱应用程序,用户可以在其中查看食谱、列出成分、获取购物清单等。
每个食谱都是由步骤组成的,每个步骤都有配料,每个配料都有一个杂货店。
我很确定创建这些链接的方法是通过模型,所以我的模型看起来像这样
类配方 :destroy has_many :ingredients, :through => :steps has_many :groceries, :through => :ingredients 结尾 类步骤 :destroy has_many :groceries, :through => :ingredients 接受嵌套属性:成分 结尾 类成分 :ingredients has_and_belongs_to_many :recipes, :through => :ingredients 结尾我可以输出调试@recipe.steps、@recipe.ingredients,但@recipe.groceries 返回
未初始化的常量 Recipe::Grocery我认为这是连接的问题,但我不明白为什么需要在控制器中指定连接。
控制器很简单
定义显示 @recipe = Recipe.find(params[:id]) respond_to 做 |格式| format.html # show.html.erb format.xml { 渲染 :xml => @recipe } 结尾 结尾我是否在正确的地方寻找我的错误?还是我误解了错误??
【问题讨论】:
标签: ruby-on-rails join