我有 3 个模型:
- 帖子
- 注释
- 问题
评论属于帖子,问题属于评论。在我的帖子索引页面上,我显示了所有帖子以及属于每个帖子的最后一条评论。当试图将最后一条评论链接到问题索引页面时,我的问题就出现了。这就是我尝试这样做的方式:
<%= link_to (post.comments.last.try(:[],:body)), comment_questions_path(@comment) %>
我得到的错误:
Couldn't find Comment with id=questions
这是我的routes.rb
文件:
resources :posts do
resources :comments
end
resources :comments do
resources :questions
end
和comment_questions_path
我跑步的时候rake routes
:
comment_questions GET /comments/:comment_id/questions(.:format) questions#index
服务器日志:
Started GET "/comments//questions" for 127.0.0.1 at 2013-09-25 20:23:14 -0400
ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by CommentsController#show as HTML
Parameters: {"id"=>"questions"}
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."id" = ? LIMIT 1 [["id", "questions"]]
Completed 404 Not Found in 66ms