Reputation: 13558
I get this error when deleting a 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.
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.)
Upvotes: 0
Views: 66
Reputation: 15605
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"?
Upvotes: 0
Reputation: 83680
Seems like you haven't got
has_many :comment_titles
in your User
model
Upvotes: 3