I have this in my models/comment.rb
However it returns error when the user was deleted.
How can I make it return ‘Not Found User’ when the user was deleted?
models/comment.rb
def self.last_comment_nickname
order("id").last.user.profile.nickname
end
Use the andand gem:
Or just write code; honestly if you’re not sure how to check a value for null I’m afraid just telling you would do more harm than good in the long run.
Although I might delegate profile methods to the user.