user730569
user730569

Reputation: 4004

Why can't I access this method defined in my model from inside my controller?

I have this method in my videos controller:

def notifications
  erase_notification_count
end

It calls the erase_notification_count method defined in my user model:

def erase_notification_count
  new_notification_count += (self.notifications.count * (-1))
end

This is the error I get:

NameError in VideosController#notifications

undefined local variable or method `erase_notification_count' for #<VideosController:0x102f0fed0>

Why am I getting this error? How do I fix it?

Upvotes: 1

Views: 1248

Answers (1)

jesse reiss
jesse reiss

Reputation: 4579

You defined the erase_notification_count on the User model, this means you must call it on a User object. You're trying to call it directly on the VideosController object.

Upvotes: 5

Related Questions