lundi 17 octobre 2016

Rials 4, SQ Lite 3: NoMethodError - undefined method: nil:NilClass

I've created a Notification Model which belongs_to a User (Devise) and each User has_many Notifications.
However I somehow can't get the Notifications in my Applications Controller or any other Controller:

def notifications
    @notifications = current_user.notifications.order('created_at desc')
end

I always seem to get nil as Object.

For example:
Recipes / Search View:

- if @notifcations.exists?

gives me this error:

NoMethodError
undefined method `exists?' for nil:NilClass

Thanks in advance for any help!

Aucun commentaire:

Enregistrer un commentaire