【问题标题】:Rails, ActionCable, send message to Channel from serverRails,ActionCable,从服务器向 Channel 发送消息
【发布时间】:2018-03-29 01:27:51
【问题描述】:

有什么方法可以将消息发送到频道,例如,

此命令从服务器发送到客户端

ActionCable.server.broadcast('test_notification_channel', {t: 1})

但我需要从控制器直接发送到频道

【问题讨论】:

    标签: ruby-on-rails actioncable


    【解决方案1】:

    虽然我认为它可以通过其他方式完成,包括 action: 应该可以工作,假设您的频道有 stream_for "test_notification_channel"

    ActionCable.server.broadcast \
      "test_notification_channel", { action: "method_on_channel", t: "1" }
    

    【讨论】:

    • 不,它不起作用。谢谢您的回答!现在,我在模型中使用一个方法,然后,我可以从任何地方调用它。
    猜你喜欢
    • 2013-06-04
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多