ruby-on-rails-5 - 发生 WebSocket 错误 : wrong number of arguments (given 2, 预期 1)

标签 ruby-on-rails-5 actioncable

我尝试创建与有线服务器的连接并订阅 channel ,但出现日志错误:

Started GET "/cable" for 172.20.0.1 at 2017-05-27 08:29:39 +0000
Started GET "/cable/" [WebSocket] for 172.20.0.1 at 2017-05-27 08:29:39 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
WebSocket error occurred: wrong number of arguments (given 2, expected 1)

我的代码:

// order_slots.coffee
jQuery(document).ready ->
  //some jquery code that call create_channel function

create_channel = (order_id) ->
  App.cable.subscriptions.create {
    channel: "OrderSlotsChannel",
    order_id: order_id
  },
    connected: ->
    # Called when the subscription is ready for use on the server

    disconnected: ->
      # Called when the subscription has been terminated by the server

    received: (data) ->
      # Data received

具体 channel :

//order_slots_channel
class OrderSlotsChannel < ApplicationCable::Channel
  def subscribed
    stream_from "order_slots_#{params[:order_id]}_channel"
  end

  def unsubscribed; end
end

与ActionCable连接:

# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
      logger.add_tags 'ActionCable', current_user.email
    end

    protected

    def find_verified_user
      verified_user = env['warden'].user
      verified_user || reject_unauthorized_connection
    end
  end
end

ActionCable::Channel::Base - 只是空的。我将不胜感激任何帮助。提前致谢

最佳答案

我解决了这个问题。该项目使用 Passenger Phusion 作为应用服务器,5.0.x 版本与 Rails 5.1 和 Action Cable 结合不好。您应该将乘客更新至 5.1.x

关于ruby-on-rails-5 - 发生 WebSocket 错误 : wrong number of arguments (given 2, 预期 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44214877/

相关文章:

ruby-on-rails - 在带有 Action 电缆的 rails 中,无法从客户端发送到服务器

ruby-on-rails - 如何在permit + Rails中合并嵌套属性

ruby-on-rails - 为什么我的 Rails 容器没有连接到我的 Postgres 容器?

ruby - 将 Rails 从 5.1 升级到 5.2 后,我收到以下警告消息

ruby-on-rails - 如何向 Rails 5 中的现有类添加方法?

ruby-on-rails-4 - ActionCable 连续连接/断开环路

使用 Action-Cable 的 Ruby-on-Rails 应用程序在开发中运行,但在生产模式中失败

ruby-on-rails - 乘客使用比预期更多的 PostgreSQL 连接

ruby-on-rails - 我如何解析一个 Excel 文件,它会给我提供与视觉上完全一样的数据?

ruby-on-rails - 跟踪 Rails 和 Heroku 上的 ActionCable 性能