[英]how to get a notification when there is a new post [ruby on rails]
任何人都知道如何創建通知。在紅寶石中彈出。 我有一個ruby應用程序,我希望在其中任何管理員發布新文章時,其他用戶自動自動彈出該應用程序,而當他們不在線時,當他們登錄該應用程序時也應該顯示該應用程序
使用觀察者或使用after_save回調 。 請注意,如果選擇回調方法,則返回值將被忽略。 觀察者的示例如下:
# in your model class
after_save :send_create_notifications
private
def send_create_notifications
users.notifications << model
end
和回調版本:
# No indication of the callback's existence in your model class
class NotificationObserver < ActiveRecord::Observer
observe MyModel
def after_create(model)
users.notifications << model
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.