'Rails "noticed gem" saying uninitialized constant

I am trying to get notifications to work in my app. I found "noticed gem" from this GitHub repo and followed all the steps that he does. I have the gem in my gem file, I did bundle install and update and rails db:migrate and everything. However when I try running this in rails console

CommentNotification.with(post: @post).deliver(current_user)

I get

 Traceback (most recent call last):
    1: from (irb):1
NameError (uninitialized constant CommentNotification)

This is my comment_notification.rb class that gets generated under app/notifications/comment_notificaiton.rb when I run rails generate noticed:notification CommentNotification just as he does in the video and just as the documentation suggests.

# To deliver this notification:
#
CommentNotification.with(post: @post).deliver_later(current_user)
CommentNotification.with(post: @post).deliver(current_user)

class CommentNotification < Noticed::Base
  # Add your delivery methods
  #
  deliver_by :database
  # deliver_by :email, mailer: "UserMailer"
  # deliver_by :slack
  # deliver_by :custom, class: "MyDeliveryMethod"

  # Add required params
  #
  param :post

  # Define helper methods to make rendering easier.
  #
  def message
    t(".message")
  end
  #
  def url
    post_path(params[:post])
  end
end


Solution 1:[1]

A bit late to this, but manually loading the notification class in rails console solved this issue in my case, i.e.: load "app/notifications/comment_notification.rb". (PS: I would also check the spelling of the file name, i.e. comment_notification vs comment_notificaiton)

Solution 2:[2]

You have to restart your spring server.

Using bin/spring stop command, the spring server will be stopped. Then the server will be started using rails server or rails s.

Solution 3:[3]

Uncomment the first two lines:

# CommentNotification.with(post: @post).deliver_later(current_user)
# CommentNotification.with(post: @post).deliver(current_user)

remember, @post must be the resource that you are going to store in user notifications

user.notifications

@post must exist

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zengetsu
Solution 2 Debanjan Dey
Solution 3 Samuel Da Costa