Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
websocket rails javascript不工作_Javascript_Ruby On Rails_Websocket - Fatal编程技术网

websocket rails javascript不工作

websocket rails javascript不工作,javascript,ruby-on-rails,websocket,Javascript,Ruby On Rails,Websocket,我使用websocket rails频道,并从sidekiq工作者处触发它。触发器正确地记录在websocket rails日志中,如下所示,并删除 它会像这样被触发: channel = "station" + station_id.to_s WebsocketRails[:"#{channel}"].trigger(:new, stationsong) var dispatcher = new WebSocketRails('localhost/websocket'); var stati

我使用websocket rails频道,并从sidekiq工作者处触发它。触发器正确地记录在websocket rails日志中,如下所示,并删除 I[2014-12-31 16:19:28.788][Channel][station10938]#StationSongs#id:54a41400446562680e17c102,名称:“Fedde&Direct Le Grand”,标题:“梦之舞第73-14卷-我们的归属”,信息:无,周:1,年:2014,日期:2014-12-31 15:19:28 UTC,站号:10938>

它会像这样被触发:

channel = "station" + station_id.to_s
WebsocketRails[:"#{channel}"].trigger(:new, stationsong)
var dispatcher = new WebSocketRails('localhost/websocket');
var stationid = $('#songhistorylist').data("id"); // is 10938
var stationname = 'station' + String(stationid);
var channel = dispatcher.subscribe(stationname);
console.log(channel);
channel.bind('new', function (song) {
        console.log(song);
        console.log('a new song about ' + song.name + " - " + song.title + ' arrived!');
});
然后我设置了订阅频道站10938,javascritp代码如下所示:

channel = "station" + station_id.to_s
WebsocketRails[:"#{channel}"].trigger(:new, stationsong)
var dispatcher = new WebSocketRails('localhost/websocket');
var stationid = $('#songhistorylist').data("id"); // is 10938
var stationname = 'station' + String(stationid);
var channel = dispatcher.subscribe(stationname);
console.log(channel);
channel.bind('new', function (song) {
        console.log(song);
        console.log('a new song about ' + song.name + " - " + song.title + ' arrived!');
});
这将只打印出通道,而不打印任何其他内容,即使该通道一直出现在日志中


我做错了什么?

行:
WebsocketRails[:“{channel}]”。触发器(:new,stationsong)
,删除“:”

它应该是:
WebsocketRails[“station#{station _id}]”。触发器(:new,stationsong)
在JS中,调度程序应如下所示:
var dispatcher=new WebSocketRails(window.location.host+'/websocket')
,因为您的服务器端口可能会更改

您的服务器应该有(假设
stationsong
设置正确):

您的客户端JS应该具有:

var dispatcher = new WebSocketRails(window.location.host + '/websocket')
var stationid = $('#songhistorylist').data("id"); // is 10938
var stationname = 'station' + String(stationid);
var channel = dispatcher.subscribe(stationname);
console.log(channel);
channel.bind('new', function (song) {
        console.log(song);
        console.log('a new song about ' + song.name + " - " + song.title + ' arrived!');
});

你找到解决办法了吗?我也有同样的问题。。