2017-05-27 72 views
1

我嘗試創建連接到電纜服務器和訂閱的頻道,但我得到的錯誤與日誌:WebSocket的錯誤:錯誤的參數數目(假設2,預計1)

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 

具體信道:

//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 - 只是空的。我會感謝任何幫助。在此先感謝

+0

你檢查你的這段代碼:'create_channel =(ORDER_ID) - > App.cable.subscriptions.create { 聲道: 「OrderSlotsChannel」, ORDER_ID:ORDER_ID }' 我認爲它應該只有一個參數即通道名稱,即「order_slots _#{order_id} _channel」 –

回答

2

我解決了這個問題。該項目使用Passenger Phusion作爲應用服務器,5.0.x版本與Rails 5.1和動作電纜嚴重結合。您應該更新乘客最多的5.1.x

相關問題