gpt4 book ai didi

ruby-on-rails - 来自控制台的 ActionCable.server.broadcast

转载 作者:行者123 更新时间:2023-12-02 18:22:08 24 4
gpt4 key购买 nike

我可以在 Controller 中使用以下代码,但不能在控制台中使用(都是开发环境)。我正在使用 Rails 5.0.0.beta2。

ActionCable.server.broadcast 'example_channel', message: '<p>Test</p>'

控制台:

>> ActionCable.server.broadcast 'example_channel', message: '<p>Test</p>'
[ActionCable] Broadcasting to example_channel: {:message=>"<p>Test</p>"}
=> []

如何在控制台中使用它?

最佳答案

ActionCable 在开发模式下的默认行为是使用async 适配器,该适配器仅在同一进程中运行。对于进程间广播,您需要切换到 redis 适配器。

要在开发模式下启用redis,您需要编辑config/cable.yml:

redis: &redis
adapter: redis
url: redis://localhost:6379/1

production: *redis
development: *redis
test: *redis

关于ruby-on-rails - 来自控制台的 ActionCable.server.broadcast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35176934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com