控制台中的 ActionCable.server.broadcast [英] ActionCable.server.broadcast from the console

查看:43
本文介绍了控制台中的 ActionCable.server.broadcast的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can use the following code in the controller but not in the console (both development environment). I'm using 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>"}
=> []

如何在控制台中使用它?

How can I use it in the console?

推荐答案

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

The default behavior for ActionCable in development mode is to use the async adapter, which operates within the same process only. For inter-process broadcasting, you will need to switch to the redis adapter.

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

To enable redis in development mode, you will need to edit config/cable.yml:

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

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

这篇关于控制台中的 ActionCable.server.broadcast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆