我在我的機器上運行ActionCable時遇到問題。TypeError:App.cable未定義
在資產/ Java腳本/渠道我有兩個文件:
index.coffee
#= require action_cable
#= require_self
#= require_tree .
@App = {}
App.cable = ActionCable.createConsumer()
和question.coffee
App.question = App.cable.subscriptions.create "QuestionChannel",
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) ->
# Called when there's incoming data on the websocket for this channel
follow: ->
@perform 'follow'
unfollow: ->
@perform 'unfollow'
我的application.js文件看起來像這樣:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require icheck
//= require homer/scripts
//= require Chart
//= require excanvas
//= require channels
//= require_tree .
當我開始電纜服務器和軌道服務器和本地主機訪問:在Firefox控制檯3000我看到了兩個錯誤:
SyntaxError: An invalid or illegal string was specified
this.webSocket = new WebSocket(this.consumer.url);
和
TypeError: App.cable is undefined
App.question = App.cable.subscriptions.create("QuestionChannel", {
我使用的是軌道5測試版3.我該如何解決這個?
所以'ActionCable.createConsumer()'必須返回undefined。 – epascarello
當我在Firefox控制檯鍵入'''ActionCable.createConsumer()'''返回'''語法錯誤:指定了無效的或非法的串this.webSocket =新的WebSocket(this.consumer.url);''' –
那麼'this.consumer.url'的價值是什麼? – epascarello