Link_to rails嵌套表单编辑

我刚刚按照以下教程进行了很好的工作。 http://www.communityguides.eu/articles/6

然而,有一件事他对我来说很难,那就是编辑。

我打电话给我的link_to编辑了

 

然后,它带我到一个错误的页面,不知道为什么。

 NoMethodError in Comments#edit Showing /home/jean/rail/voyxe/app/views/comments/_form.html.erb where line #1 raised: undefined method `comment_path' for #<#:0xb65924f8> Extracted source (around line #1): 1:  2:  3: 
4:

prohibited this comment from being saved:

现在这里是评论编辑中的表格

   

prohibited this comment from being saved:


这是控制器文章控制器显示

  @article = Article.find(params[:id]) @comments = @article.comments.find(:all, :order => 'created_at DESC') 

评论控制器编辑

  def edit @comment = Comment.find(params[:id]) end 

看起来它是一个嵌套资源,因此您需要指定包含commentarticle 。 例如:

 <%= form_for [@article, @comment] do |f| %> 

comment_path是一个未定义的方法,因为没有路由在顶层公开注释。 它有时有助于运行rake routes以查看可用的路线。

更新:

您链接的文章仅提供评论的createdelete操作。 如果您需要支持编辑操作,则需要通过更改以下内容来修改路由:

 resources :comments, :only => [:create, :destroy] 

至:

 resources :comments, :only => [:create, :destroy, :edit, :update] 

您还需要实现编辑和更新操作 – 按照惯例编辑将显示表单,更新将处理表单提交。 您还需要确保编辑视图中的@article可用。