【发布时间】:2018-03-22 06:25:12
【问题描述】:
在 Rails 5 中,我使用ActionCable 实时广播通知。一旦创建Notification 对象,就会发生广播。现在我想在Notification 对象被删除时恢复广播通知。
在notification_broadcast_job.rb中,
def perform(notification, user_id)
ActionCable.server.broadcast "notifications:#{user_id}", data: NotificationSerializer.new(notification)
end
在notification.rb中,
after_commit :broadcast_notification
private
def broadcast_notification
users.each do |user|
NotificationsBroadcastJob.perform_later(self, user.id)
end
end
现在的问题是,当用户 A 喜欢属于用户 B 的一篇帖子时,B 将收到通知(无需重新加载页面)。当用户 A 立即不喜欢它时,应该从用户 B 发出通知(无需重新加载页面)。现在删除的对象(通知)将简单地显示在一个列表中。
我该如何解决这个问题?请帮帮我。
【问题讨论】:
标签: ruby-on-rails ruby notifications broadcast actioncable