其实我在动感线缆上有点迷惑。问题是,我想要发送通知给每个特定的用户,他们的id出现在我的payment table.And中,我在控制器操作中多次尝试ActionCable.server.broadcast。但它显示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注: payment belongs_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".):发布于 2020-04-27 05:46:51
DoubleRenderError是由于在迭代器中使用了render。我对Action Cable不是很熟悉,但更改为render_to_string可能会有所帮助。
https://stackoverflow.com/questions/61447993
复制相似问题