【发布时间】:2017-11-25 11:20:06
【问题描述】:
我正在尝试在我的 Rails 项目中使用 ActionCable,虽然似乎正在建立 WebSocket 连接,但没有发送任何消息(仅 ping)。
据我所知,我的 CoffeeScript 中的 connected 方法从未被调用过。
这是我的频道定义:
# app\channels\quiz_data_channel.rb:
class QuizDataChannel < ApplicationCable::Channel
def subscribed
stream_from "quiz_data"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
这是我的咖啡脚本:
#app\assets\javascripts\channels\quiz_data.coffee:
App.quiz_data = App.cable.subscriptions.create "QuizDataChannel",
connected: ->
# Called when the subscription is ready for use on the server
console.log "[AC] on click handler called?"
$('btn btn-primary btn-lg').on 'click', console.log "[AC] on click handler called!"
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
有人知道问题可能是什么吗?
这是我的第一个 Rails 项目,我们将不胜感激。
【问题讨论】:
标签: ruby-on-rails websocket coffeescript actioncable