【问题标题】:Rails "noticed gem" saying uninitialized constantRails“注意到宝石”说未初始化的常量
【发布时间】:2021-07-16 02:39:10
【问题描述】:

我正在尝试让通知在我的应用程序中工作。我从this GitHub repo 中找到了“引人注目的宝石”,并按照他所做的所有步骤进行操作。我的 gem 文件中有 gem,我做了 bundle install 和 update 以及 rails db:migrate 和一切。但是,当我尝试在 rails 控制台中运行它时

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

我明白了

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

这是我在 app/notifications/comment_notificaiton.rb 下生成的 comment_notification.rb 类,当我运行 rails generate noticed:notification CommentNotification 时,正如他在视频中所做的那样,正如文档所建议的那样。

# 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

【问题讨论】:

  • 它不起作用。我已经尝试重新加载!,并一起重新启动控制台,以及 VSCode 本身。

标签: ruby-on-rails ruby console


【解决方案1】:

你必须重启你的 spring 服务器。

使用bin/spring stop 命令,spring server 将被停止。然后将使用rails serverrails s 启动服务器。

【讨论】:

    【解决方案2】:

    取消前两行的注释:

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

    请记住,@post 必须是您要存储在用户通知中的资源

    user.notifications
    

    @post 必须存在

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多