我可以在 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/