ActionCable没有在javascript中执行订阅

Arn*_*Roa 5 javascript ruby-on-rails actioncable

我正在玩ActionCable,这是一个非常基本的设置.

我在客户端这个:

App.chat = App.cable.subscriptions.create "ChatChannel",
  subscribed: ->
    console.log 'subscribed'
  test: ->
    @perform("test")
Run Code Online (Sandbox Code Playgroud)

在服务器上

class ChatChannel < AC..::Channel
  def subscribed
    Rails.logger.info "This is never printed in the logs"
  end
  def test
    Rails.logger.info "This is never printed in the logs"
  end
end
Run Code Online (Sandbox Code Playgroud)

在JS控制台上我可以看到:

[ActionCable] Opening WebSocket, current state is null, subprotocols: actioncable-v1-json,actioncable-unsupported 1494360634092
[ActionCable] ConnectionMonitor started. pollInterval = 3000 ms 1494360634096
[ActionCable] WebSocket onopen event, using 'actioncable-v1-json' subprotocol 1494360634733
[ActionCable] ConnectionMonitor recorded connect 1494360634734
Run Code Online (Sandbox Code Playgroud)

在服务器日志中,我看到:

Started GET "/cable" for 127.0.0.1 at 2017-05-09 15:10:34 -0500
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 09/05/2017 03:10 PM
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Registered connection (Z2lkOi8vcHJvcGhvL1VzZXIvMg)
Run Code Online (Sandbox Code Playgroud)

如果我从服务器发送广播消息,则从未在客户端上收到.如果我尝试从客户端执行操作,则返回false并且控制台上没有任何内容.

网络选项卡显示:

Request URL:ws://0.0.0.0:3000/cable
Request Method:GET
Status Code:101 Switching Protocols (with a green status icon)
Run Code Online (Sandbox Code Playgroud)

我没有使用redis,启动服务器 rails server

gem 'rails', '~> 5.0.2'
gem 'puma', '~> 3.0'
Run Code Online (Sandbox Code Playgroud)

zar*_*aru 0

尝试一下。

App.chat = App.cable.subscriptions.create "ChatChannel",
  # subscribed: ->
  #   console.log 'subscribed'
  # test: ->
  #   @perform("test")

  connected: ->
    @perform("test")
Run Code Online (Sandbox Code Playgroud)