0

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

resources :posts do
 resources :comments do
 end
end

resources :comments do
 resources :questions do
 end
end

我正在尝试使用以下内容从 _post 部分(在帖子索引视图中调用)链接到 comment_questions 路径:

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

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

4

1 回答 1

0

如果您链接到 QuestionsController 的 show 操作,您应该将评论和问题对象传递给 comment_question_path(comment, question)

为 comment_question_path 生成的 url 将是

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

随着你正在做的事情,comment_questions_path(post, comment)它将使用 post id 来评论和评论 id 来提问,你会去一个完全不同的页面

于 2013-10-14T18:35:46.003 回答