类型错误: 应用程序电缆未定义
TypeError: App.cable is undefined
我在机器上运行ActionCable时遇到问题。
在资产/javascripts/channels中,我有两个文件:
索引.咖啡
#= require action_cable
#= require_self
#= require_tree .
@App = {}
App.cable = ActionCable.createConsumer()
和问题咖啡
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'
我的应用程序.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 .
当我启动有线服务器和 rails 服务器并在 Firefox 控制台中访问 localhost: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
需要一个参数 - 地址到Action Cable服务器。
@App = {}
App.cable = ActionCable.createConsumer("ws://cable.example.com")
如果您错过了此参数,则this.customer.url
未定义。
确保你有
<%= action_cable_meta_tag %>
在应用程序布局中的某个位置。
默认情况下,Rails 会生成,它负责将电缆 URL 提供给 Action Cable,这样您就不必将其传递给
ActionCable.createConsumer()
.
我遇到了同样的问题。我将服务器更改为 puma whaaala,它起作用了!
您可以通过添加gem 'puma'
并运行bundle
来进行更改。
另外,请确保在 development.rb 文件中config.action_cable.url = "ws://localhost:3000/cable"
。祝你好运
相关文章:
- 使用jquery.load('pageName')方法时,未从应用程序缓存加载Html页
- 注入应用程序的角度控制器未定义
- Ionic应用程序在部署后给出ReferenceError:未定义Promise
- Rally自定义应用程序复选框筛选器不工作
- 如何在自定义应用程序中使用后退按钮访问Fiori启动板
- 创建 JavaScript 自定义应用程序的新实例
- 如何定义应用程序的方法
- 尝试使用 SharePoint 2013 的 REST 服务器和 CSOM 时,“未为此应用程序的请求 URL 部署应用
- 从网页打开自定义应用程序
- 未捕获的引用错误:未定义应用,未捕获的语法错误:意外的令牌<.缺少一些东西
- AJAX加载的内容中未定义引导程序日期选择器
- 自定义应用程序启动屏幕
- 自定义应用程序的动态高度
- 绑定后未定义应用程序
- Ext.JS 4.2.1使用Jasmine进行单元测试-未定义应用程序
- 在angular js中的一个单独文件中定义应用程序
- 使用node.js一步一步创建自定义应用程序
- Digital Publishing Suite Web Viewer未显示应用程序
- 有没有办法让窗口在窗口中包含自定义应用程序
- 由于日光节约已经开始,我的自定义应用程序不工作