-
StackOverflow 文档
-
Ruby on Rails 教程
-
ActionCable
-
基本客户端(Coffeescript)
应用程序/资产/ Javascript 角/信道/ notifications.coffee
App.notifications = App.cable.subscriptions.create "NotificationsChannel",
connected: ->
# Called when the subscription is ready for use on the server
$(document).on "change", "input", (e)=>
@notify(e.target.value)
disconnected: ->
# Called when the subscription has been terminated by the server
$(document).off "change", "input"
received: (data) ->
# Called when there's incoming data on the websocket for this channel
$('body').append(data)
notify: (data)->
@perform('notify', data: data)
app / assets / javascripts / application.js#通常是这样生成的
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
app / assets / javascripts / cable.js#通常是这样生成的
//= require action_cable
//= require_self
//= require_tree ./channels
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
}).call(this);