简体   繁体   English

为什么会出现此错误?

[英]Why am I getting this error?

I get this error when deleting a comment_title : 删除comment_title时出现此错误:

NoMethodError in Comment titlesController#destroy

undefined method `comment_titles' for #<User:0x102e63bf8>

This is the destroy method: 这是销毁方法:

def destroy
  @comment_title = current_user.comment_titles.find(params[:id])
  @comment_title.destroy
  respond_to do |format|
    format.html {redirect_to :back}
  end
end

and the error refers to this line: 错误涉及此行:

@comment_title = current_user.comment_titles.find(params[:id])

I don't understand what's going on here. 我不明白这里发生了什么。 Is it saying that current_user is nil? 是说current_user为nil吗? That doesn't make sense because I am logged in, and current_user works in other parts of my app. 那没有意义,因为我已经登录,并且current_user在我的应用程序的其他部分中工作。 This also worked before, but after a lot of changes in my app, it doesn't work all of a sudden. 之前也可以使用,但是在我的应用程序中进行了很多更改后,它并不是突然起作用。

What's wrong and how do I fix it? 有什么问题,我该如何解决?

(Please don't ask me what I did from now until when deleting worked. I've done far too much stuff for it to be helpful.) (请不要问我从现在开始直到删除有效为止的工作。我已经做了太多工作,以至于无济于事。)

Seems like you haven't got 好像你还没有

has_many :comment_titles

in your User model 在您的User模型中

It's saying that User objects don't have a method "comment_titles". 就是说User对象没有方法“ comment_titles”。 I can't be more specific without seeing your model code but I suggest that you look there for further clues. 在没有看到您的模型代码的情况下,我不能说得更具体,但我建议您在那儿寻找进一步的线索。 Is there a method or association called "comment_titles"? 是否有一种称为“ comment_titles”的方法或关联?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM