2016-03-03 4 views
2

У меня возникла проблема с запуском ActionCable на моей машине.ТипError: App.cable не определено

В активах/JavaScripts/каналов У меня есть два файла:

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 . 

Когда я начинаю кабельный сервер и сервер рельсов и посетить Localhost: 3000 в FireFox консоли я вижу две ошибки:

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 Beta 3. Как я могу исправить это?

+1

Так что 'ActionCable.createConsumer()' должен возвращаться не определен. – epascarello

+0

Когда я набираю консоль firefox '' 'ActionCable.createConsumer()' '', он возвращает '' 'SyntaxError: указана недопустимая или недопустимая строка this.webSocket = новый WebSocket (this.consumer.url);' '' –

+0

Итак, какова ценность 'this.consumer.url'? – epascarello

ответ

1

ActionCable.createConsumer требуется один параметр - адрес к серверу действия.

@App = {} 
App.cable = ActionCable.createConsumer("ws://cable.example.com") 

Если вы пропустите этот параметр, то this.customer.url не определен.

0

Убедитесь, что у вас есть

<%= action_cable_meta_tag %> 

где-то в макете applicaiton.

Rails по умолчанию генерирует и заботится о предоставлении кабеля URL для кабеля действий, так что вы не должны передать его

ActionCable.createConsumer() 

.