在Rails应用程序中未初始化的常量



我正在做一个rails应用程序,但我有这个问题,我无法解决。我正在尝试设置通知,但这是关于初始化常量发生的错误,但我有这个类,我检查它是否在单数上,所以我不知道为什么比较这个。请帮帮我。

class GroupNotification < Noticed::Base
# Add your delivery methods
#
deliver_by :database
end
class Notification < ApplicationRecord
include Noticed::Model
belongs_to :recipient, polymorphic: true
end

class Group < ApplicationRecord
#statement che associa un group all'utente che lo crea      
belongs_to :user
has_many :members
has_many :roles
has_many :partecipation

#has_noticed_notifications param_name: :group, model_name: "Notification"
after_create_commit :notify_recipient
has_many :notifications, as: :recipient, dependent: :destroy
before_destroy :remove_partecipation, if: :has_partecipation?
before_destroy :cleanup_notifications

private
def notify_recipient
GroupNotification.with(group: self).deliver_later(self.user)
end
def cleanup_notifications
notifications_as_group.destroy_all
end

问题是

NameError in GroupsController#create
uninitialized constant Group::GroupNotification
Extracted source (around line #130):
128
129
130
131
132
133

def notify_recipient
GroupNotification.with(group: self).deliver_later(self.user)
end
private

无论这段代码被调用,它似乎是在Group模块,所以当你引用GroupNotification红宝石假设你的意思是相对于当前模块"你在"(Group).

你可以用::GroupNotification代替GroupNotification来修复它。

我还怀疑您没有粘贴所有相关代码,因为输出显示

NameError in GroupsController#create

但在您的示例中,GroupController被引用的唯一地方是在Group模型中。

相关内容

  • 没有找到相关文章

最新更新