将数据传递给ActionCable disconnect方法

时间:2017-06-15 17:53:40

标签: ruby-on-rails ruby-on-rails-5 actioncable

有没有办法可以将数据传递给客户端ActionCable通道的disconnect方法?我需要当前用户的ID,以便我可以关闭他们的在线状态指示器。我已经尝试并阅读了我在ActionCable上可以找到的所有内容,但我不明白如何将数据传递给接收以外的方法。

Live.appearance = Live.cable.subscriptions.create('AppearanceChannel', {

  // need to pass the user's ID here:
  disconnected: function(data) {
    var userId = data['appearances'][0];
    var appearanceContainer = $('.user-status-indicator').filter('#' + userId);
    appearanceContainer.remove();
  },

  received: function(data) {
    var userId = data['appearances'][0];
    var appearanceContainer = $('.appearance-label').filter('#' + userId);
    appearanceContainer.append('<div class="user-status-indicator" id="${userId}"></div>');
  }

});

0 个答案:

没有答案