任何人都知道如何在 ruby on rails 中创建通知弹出窗口。我有一个 ruby 应用程序,当任何管理员发布新文章时,它应该会在其他用户自动弹出时弹出,当他们不在线时,它也应该在他们登录应用程序时出现
问问题
115 次
1 回答
0
使用观察者或使用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
于 2013-05-12T18:25:16.910 回答