我正在建立一个相当简单的食谱网站来学习RoR,而且我一直在遵循入门指南,除了我已将食谱的帖子交换和对成分的评论交换了。我一路删除评论(成分)http://edgeguides.rubyonrails.org/getting_started.html#deleting-comments
现在我遇到一个错误
#的未定义方法“配方”
引起问题的部分中的线在这里
<%= link_to'删除成分',[ingredient.recipe_id,成分], :confirm =>'您确定', :method =>:delete%>
控制器方法(我认为没有任何作用,但我不确定)
def破坏 @recipe = Recipe.find(params [:recipe_id]) @ingredient = @ recipe.ingredient.find(params [:id]) @ ingredient.destroy redirect_to post_path(@recipe) 结束
我在link_to中使用“ recipe_id”,因为当我输出调试时,它没有“ recipe”属性,但是具有配方_id属性。
调试的输出是
---!ruby / object:成分 属性: id:3 成分:测试 数量:10 措施:“ 10” 描述:“ 10” recipe_id:2 created_at:2010-09-06 22:16:17.599217 Updated_at:2010-09-06 22:16:17.599217 attribute_cache:{} 更改属性:{} 销毁:错误 marked_for_destruction:假 new_record:否 先前已更改:{} 只读:false
我假设[ingredient.recipe_id,成分]只是变量的哈希?那是对的吗?我是从错误的角度出发吗?