Example
app/assets/javascripts/channels/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 # usually generated like this
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
app/assets/javascripts/cable.js # usually generated like this
//= require action_cable
//= require_self
//= require_tree ./channels
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
}).call(this);