TLDR: What is Rails' ActionCable?

Basics
Action cable allows real-time features in ruby using Websockets using the Publish Subscribe pattern

Server Side
Services maintain connections to client /consumers,/ there is one consumer to connection per browser (tab). Usually a connection is maintained and carried with the save cookie used to log in.

A channel is a logical unit of work (controller in MVC)

A consumer subscribes to a channel as a subscription, messages are routed to this channel

Client Side
Consumers need a connection instance on their side via JavaScript.

Subscriber
An example of a subscription

#
app/assets/javascripts/cable/subscriptions/appearance.coffee

App.cable.subscriptions.create { channel: "AppearanceChannel"} 


Interactions between Server-Client

A stream is way for channels to route content (as broadcasts) to subscribers

# app/channels/chat_channel.rb

class ChatChannel < ApplicationCable::Channel
  def subscribed 
    stream_from "chat_#{params[:room]}"
  end
end

A broadcast is a pub/sub link, allowing you to directly publish to a channel of subscribers.

WebNotificationsChannel.broadcast_to(
  current_user,
  title: 'New things!',
  body: 'All the news fit to print'
)