Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails-控制器操作中的类_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails Rails-控制器操作中的类

Ruby on rails Rails-控制器操作中的类,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,在我看来,我有- <%= link_to 'remove pdf', controller: 'chap_comments', action: 'remove_file', id: comment.id %> 。。。我得到了未定义的方法删除\u chap\u comment\u pdf!'对于nil:NilClass`-为什么不识别该类 类似地,以下是- <%= link_to 'remove pdf', remove_file_chap_comment_path(:id),

在我看来,我有-

<%= link_to 'remove pdf', controller: 'chap_comments', action: 'remove_file', id: comment.id %>
。。。我得到了
未定义的方法
删除\u chap\u comment\u pdf!'对于nil:NilClass`-为什么不识别该类

类似地,以下是-

<%= link_to 'remove pdf', remove_file_chap_comment_path(:id), method: :delete %>

…得到相同的错误

def remove_file
  @chap_comment = ChapComment.find(params[:id)
  @chap_comment.remove_chap_comment_pdf!
  @chap_comment.save
end
您尚未找到chap注释或分配它,因此@chap_comment为零

您尚未找到chap注释或分配它,因此@chap_comment为零

您尚未找到chap注释或分配它,因此@chap_comment为零


您未找到chap注释或未分配该注释,因此@chap\u comment为零。

您正在将
链接中的
id
传递给
,但未使用它查找记录,这就是您出现此错误的原因。请使用它:-

  @chap_comment = ChapComment.find(params[:id)
  ##do anything with this @chap_comment
请参见服务器日志(控制台),您可以看到如下内容:-

Processing by ChapsController#remove_file as HTML
  Parameters: {"id"=>"9"}

这意味着-您拥有id,但没有使用它,尽管

您在
链接中传递了
id
,但没有使用它来查找记录,这就是您出现此错误的原因。使用它:-

  @chap_comment = ChapComment.find(params[:id)
  ##do anything with this @chap_comment
请参见服务器日志(控制台),您可以看到如下内容:-

Processing by ChapsController#remove_file as HTML
  Parameters: {"id"=>"9"}

这意味着-您拥有id,但没有使用它,尽管

您在
链接中传递了
id
,但没有使用它来查找记录,这就是您出现此错误的原因。使用它:-

  @chap_comment = ChapComment.find(params[:id)
  ##do anything with this @chap_comment
请参见服务器日志(控制台),您可以看到如下内容:-

Processing by ChapsController#remove_file as HTML
  Parameters: {"id"=>"9"}

这意味着-您拥有id,但没有使用它,尽管

您在
链接中传递了
id
,但没有使用它来查找记录,这就是您出现此错误的原因。使用它:-

  @chap_comment = ChapComment.find(params[:id)
  ##do anything with this @chap_comment
请参见服务器日志(控制台),您可以看到如下内容:-

Processing by ChapsController#remove_file as HTML
  Parameters: {"id"=>"9"}
这意味着-您拥有id,但没有使用它