Как отправить уведомление отдельному пользователю в рельсах с помощью кабеля действий - PullRequest
0 голосов
/ 26 апреля 2020

На самом деле я немного запутался в действии кабеля. Проблема в том, что я хочу отправить уведомление каждому указанному c пользователю, чей идентификатор присутствует в моей таблице платежей. И я пробую 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

примечание: оплата принадлежит пользователю

Метод визуализации частично

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".):

1 Ответ

0 голосов
/ 27 апреля 2020

DoubleRenderError связано с использованием render в итераторе. Я не очень знаком с Кабелем Действий, но изменение на render_to_string может помочь.

...