Ruby on rails 编辑属于帖子的评论
因此,我创建了一个博客,用户可以创建帖子,其他人可以对该帖子发表评论 我希望用户能够编辑评论 到目前为止,我所做的工作如下: 我的路线是这样的:Ruby on rails 编辑属于帖子的评论,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,因此,我创建了一个博客,用户可以创建帖子,其他人可以对该帖子发表评论 我希望用户能够编辑评论 到目前为止,我所做的工作如下: 我的路线是这样的: resources :posts do resources :comments end 当我搜索路线时,我得到: new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new edit_post_comment GET /posts
resources :posts do
resources :comments
end
当我搜索路线时,我得到:
new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new
edit_post_comment GET /posts/:post_id/comments/:id/edit(.:format) comments#edit
post_comment GET /posts/:post_id/comments/:id(.:format) comments#show
在我的视图文件中,我使用了这个,这显然是错误的
<%= link_to 'Edit Comment', edit_post_comment_path(@comment) %>
当我尝试访问帖子页面时,我遇到以下错误:
No route matches {:action=>"edit", :controller=>"comments", :id=>nil, :post_id=>nil, :format=>nil} missing required keys: [:post_id, :id]
这是我第一次在嵌套管线上工作。我读了一些教程,但没有什么真正帮助我解决这个问题。我不知道怎样才能传递这些钥匙
如果你需要任何其他信息,请让我知道,我会提供他们
非常感谢您的帮助 您需要同时传递@post和@comment实例
edit_post_comment_path(@post, @comment)
一般来说,您需要传递与路由所属资源匹配的每个实例。所以,在一条像
edit_post_path(@post)
你只能通过邮局。在post/comment嵌套路由中,可以同时传递这两个消息。在post/comment/中,您需要传递这三个资源,等等。您需要同时传递@post和@comment实例
edit_post_comment_path(@post, @comment)
一般来说,您需要传递与路由所属资源匹配的每个实例。所以,在一条像
edit_post_path(@post)
你只能通过邮局。在post/comment嵌套路由中,可以同时传递这两个消息。在帖子/评论/任何你需要传递这三个资源的地方,等等。谢谢你的帮助。这是有道理的。我试过了,但我得到了这个错误:没有路由匹配{:post_id=>,:id=>nil}缺少必需的键:[:id]是@post和@comment都设置了吗?对@comment为零,我使用comment代替。谢谢!谢谢你的帮助。这是有道理的。我试过了,但我得到了这个错误:没有路由匹配{:post_id=>,:id=>nil}缺少必需的键:[:id]是@post和@comment都设置了吗?对@comment为零,我使用comment代替。谢谢!