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? That doesn't make sense because I am logged in, and current_user works in other parts of my app. This also worked before, but after a lot of changes in my app, it doesn't work all of a sudden.
我不明白这里发生了什么。是说current_user是零吗?这没有意义,因为我已登录,而current_user在我的应用程序的其他部分工作。这之前也有用,但经过我的应用程序的大量更改后,它不会突然发挥作用。
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.)
(请不要问我从现在开始做什么,直到删除工作。我已经做了太多的事情,因为它有用。)
2 个解决方案
#1
3
Seems like you haven't got
好像你还没有
has_many :comment_titles
in your User
model
在您的用户模型中
#2
0
It's saying that User objects don't have a method "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"?
它说User对象没有方法“comment_titles”。如果没有看到您的型号代码,我就无法更具体,但我建议您在那里寻找更多线索。是否有称为“comment_titles”的方法或关联?
#1
3
Seems like you haven't got
好像你还没有
has_many :comment_titles
in your User
model
在您的用户模型中
#2
0
It's saying that User objects don't have a method "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"?
它说User对象没有方法“comment_titles”。如果没有看到您的型号代码,我就无法更具体,但我建议您在那里寻找更多线索。是否有称为“comment_titles”的方法或关联?