-
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);