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 . But it shows 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
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. I'm not very familiar with Action Cable, but change to render_to_string
might help.