2013-10-14 28 views
0

我有3个模型:帖子,评论和问题。在routes.rb中,它们看起来像这样。链接嵌套资源

resources :posts do 
resources :comments do 
end 
end 

resources :comments do 
resources :questions do 
end 
end 

我试图从彦博部分(被称为在帖子索引视图)与下面的链接到comment_questions路径:

<%= link_to (comment.body), comment_questions_path(post, comment) %> 

它链接到comment_questions路径,但都到了问题属于错误的评论。 谢谢!

回答

0

你应该在注释和问题对象传递给comment_question_path(评论,问题),如果您链​​接到QuestionsController

演出行动comment_question_path生成的URL将

GET comments/:comment_id/questions/:id questions#show 

随着你在做什么,comment_questions_path(post, comment),将使用后的ID发表评论和问题评论ID,你会去到一个完全不同的页面

+0

和另一件事是,它应该是'没有comment_question_path'路径's' – phoet

+0

这给了我'没有路线匹配缺少必需的键:[:comment_id]'错误。 – user2759575