来自控制台的ActionCable.server.broadcast
我可以在控制器中使用以下代码,但不能在控制台中使用(两个开发环境)。 我正在使用Rails 5.0.0.beta2。
ActionCable.server.broadcast 'example_channel', message: 'Test
'
控制台:
>> ActionCable.server.broadcast 'example_channel', message: 'Test
' [ActionCable] Broadcasting to example_channel: {:message=>"Test
"} => []
我怎样才能在控制台中使用它?
在开发模式下,ActionCable的默认行为是使用async
适配器,该适配器仅在同一进程中运行。 对于进程间广播,您需要切换到redis
适配器。
要在开发模式下启用redis,您需要编辑config/cable.yml
:
redis: &redis adapter: redis url: redis://localhost:6379/1 production: *redis development: *redis test: *redis