【发布时间】:2017-07-22 02:44:15
【问题描述】:
我在 Rails 5 应用程序上使用了 actioncable。下面的代码在控制器中工作,但不在控制台中。
ActionCable.server.broadcast "connector_app", content: "test message"
回复:
[ActionCable] Broadcasting to connector_app: {:content=>"test message"}
=> nil
cable.yml
development:
adapter: redis
url: redis://localhost:6379/1
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1
控制器代码(正常工作):
def sample_socket_message
ActionCable.server.broadcast "connector_app",
content: "test message",
head :ok
end
已解决的问题: 忘记在 config/initializer/redis.rb 中添加以下代码
$redis = Redis.new(:host => 'localhost', :port => 6379)
【问题讨论】:
-
我仍然有同样的问题,即使使用正确的 redis 配置,还有其他建议吗?
-
终端可以显示哪些错误信息?
-
我也解决了这个问题。我将电缆指向 redis 中的另一个 DB id,而不是应用程序的
config/initializers/redis.rb中的那个