2
我无法找到任何确凿的文章,显示如何在rails中创建通知。每个人似乎都在谈论Mailboxer,因为这是一个很好的解决方案,但除了它们的一个段落:Notify方法外,它似乎很模糊。我在Rails中创建通知系统
因此,我正在考虑创建一个属于Activity(公共活动Gem)的通知模型,然后在活动模型上使用after_create回调来调用notify方法,然后调用所讨论活动对象的notify方法。
作为图
class Comment
include PublicActivity::Model
tracked
def notify
#Loop through all involved users of this modal instance and create a Notify record pointing to the public activity
end
end
class Activity < PublicActivity::Activity # (I presume I can override the gems Activity model in my App?)
after_create :notify
private
def notify
#Call the notify function from the model referenced in the activity, in this case, comment
end
end
所以当注释模式被调用时,公共活动跟踪它,然后调用回的意见通知方法的通知模式来拯救
通知模型只会包括
user_id, activity_id, read:boolean
注:我想我最好把一切都出了控制器的,因为我认为,整个事情就在模型中更好地处理。但我愿意接受建议
感谢