我正在尝试在我的Rails项目中使用ActionCable,虽然似乎正在建立WebSocket连接但是没有消息被发送(只有ping)。
据我所知,我的CoffeeScript中的# 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
这是我的咖啡因:
$scope.chartConfig = {data:responseNifty};
有谁知道问题可能是什么?
这是我的第一个rails项目,任何帮助都将不胜感激。
答案 0 :(得分:0)
看着你的quiz_data.coffee
,你有
App.quiz_data = App.cable.subscriptions.create "QuizDataChannel"
。我相信您的quiz_data_channel
文件中需要quiz_data_channel.rb
;您已定义stream_from "quiz_data"
的位置。尝试将其更改为stream_from "quiz_data_channel"
。让我知道你是如何上场的!