[英]How to send notification to individual user in rails using action cable
Actually i am bit confuse in action cable.其实我对行动电缆有点困惑。 The issue is, i want to send notification to each specific user whose id present in my payment table.And i try ActionCable.server.broadcast multiple number of times in the controller action.
问题是,我想向我的付款表中存在 id 的每个特定用户发送通知。我在 controller 操作中多次尝试 ActionCable.server.broadcast。 But it shows AbstractController::DoubleRenderError.
但它显示 AbstractController::DoubleRenderError。
class WebNotificationsChannel < ApplicationCable::Channel
def subscribed
# stream_from "some_channel"
stream_from "notifications:#{current_user.id}"
end
end
@payments = Payment.all
@payments.each do |payment|
ActionCable.server.broadcast "notifications:#{payment.user_id}", html: notification_render(notification) , count: unseen_notification_number
end
note: payment belongs_to user注意:付款属于_to用户
def notification_render(notification)
render(partial: 'homepage/notification', locals: {notification: notification})
end
AbstractController::DoubleRenderError (Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".):
DoubleRenderError
is due to the use of render
in the iterator. DoubleRenderError
是由于在迭代器中使用了render
。 I'm not very familiar with Action Cable, but change to render_to_string
might help.我对 Action Cable 不是很熟悉,但更改为
render_to_string
可能会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.