Mid-level Track Roadmap

ActionCable: custom channels

This course studies ActionCable channels through the one channel this app runs: Turbo::StreamsChannel, from the turbo-rails gem. It explains why the app has no app/channels directory and no connection identity. It also shows how signed stream names authorize subscriptions through ActiveSupport::MessageVerifier. A throwaway channel tested with ActionCable::Channel::TestCase demonstrates stream_from and stream_for. The lessons then follow the subscription lifecycle through subscribed, reject and unsubscribed. They close by comparing a Turbo Stream refresh signal with custom JSON data sent by broadcast_to.

What you'll learn

  • ✓How Turbo::StreamsChannel subscribes, verifies stream names and rejects
  • ✓What identified_by does and what an empty identifiers set means
  • ✓How signed stream names authorize subscriptions without user identity
  • ✓How stream_from and stream_for register streams, tested with ActionCable::Channel::TestCase
  • ✓How subscribe_to_channel, reject and stop_all_streams shape the channel lifecycle
  • ✓When to broadcast a refresh signal and when to send a JSON data payload
Free preview · Lesson 1 3 min read

This app's one real channel isn't custom

app/channels/ doesn't exist in this app. It isn't empty; find app/channels finds nothing at all. Yet the roadmap page refreshes live when an admin reorders a course, over a WebSocket, through an ActionCable channel. This lesson is about the channel that does it, and the app didn't write it.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...