私のマシンで ActionCable を実行する際に問題があります。
assets/javascripts/channels には 2 つのファイルがあります。
インデックスコーヒー
#= 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 コンソールで localhost:3000 にアクセスすると、次の 2 つのエラーが表示されます。
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", {
Rails 5 beta 3 を使用しています。これを修正するにはどうすればよいですか?