actioncable和rails和Uncaught ReferenceError:数据未定义

时间:2018-12-02 17:50:04

标签: ruby-on-rails-5 actioncable

我一直在遵循ActionCable的这本https://www.pluralsight.com/guides/creating-a-chat-using-rails-action-cable手册,但由于遇到错误消息而感到困惑

未捕获的ReferenceError:数据未定义

我的room.coffe看起来像这样:

    App.room = App.cable.subscriptions.create "RoomChannel",
  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) ->
    alert(data['message'])

  speak: (message) ->
    @perform 'speak', message: message

$(document).on 'keypress', '[data-behavior~=room_speaker]', (event) ->
  if event.keyCode is 13 # return/enter = send
    App.room.speak event.target.value
    event.target.value = ''
    event.preventDefault()

并在浏览器中编译如下:

(function() {
  App.room = App.cable.subscriptions.create("RoomChannel", {
    connected: function() {},
    disconnected: function() {},
    received: function(data) {}
  });

#error is in this next line
  alert(data['message'])({
    speak: function(message) {
      return this.perform('speak', {
        message: message
      });
    }
  });

  $(document).on('keypress', '[data-behavior~=room_speaker]', function(event) {
    if (event.keyCode === 13) {
      App.room.speak(event.target.value);
      event.target.value = '';
      return event.preventDefault();
    }
  });

}).call(this);

我不确定我做错了什么,其他所有内容似乎都正常运行... 谢谢

0 个答案:

没有答案