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,但没有使用它