Ruby on rails 铁路电缆5
在这个 我几乎能理解 但只有一部分我不能Ruby on rails 铁路电缆5,ruby-on-rails,actioncable,Ruby On Rails,Actioncable,在这个 我几乎能理解 但只有一部分我不能 //javascripts/channels/rooms.coffee App.global_chat = App.cable.subscriptions.create { channel: "ChatRoomsChannel" chat_room_id: '' }, connected: -> # Called when the subscription is ready for use on the serve
//javascripts/channels/rooms.coffee
App.global_chat = App.cable.subscriptions.create {
channel: "ChatRoomsChannel"
chat_room_id: ''
},
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) ->
# Data received
send_message: (message, chat_room_id) ->
@perform 'send_message', message: message, chat_room_id: chat_room_id
方法send\u message
的内容为@执行“send\u message”,message:message,chat\u room\u id:chat\u room\u id
。将其显示为Javascript:
function(message){
return this.perform('speak', {
message: message
});
}
我的问题是执行的功能在哪里?
我试图将
@perform
修改为@performs
,但该函数无法工作。它是在rails中定义的。在这里:
您从App.cable.subscriptions.create获得的对象将具有此方法/功能。“我试图将@perform修改为@performs”-为什么?你对会发生什么的假设是什么?@SergioTulentsev我只是想知道执行功能在哪里
class ActionCable.Subscription
constructor: (@consumer, params = {}, mixin) ->
@identifier = JSON.stringify(params)
extend(this, mixin)
# Perform a channel action with the optional data passed as an attribute
perform: (action, data = {}) ->
data.action = action
@send(data)