actioncable

Presence indicator with ActionCable + Turbo Streams

Presence is usually overkill, but for collaboration features it’s valuable: show who’s online in a room. I identify connections with current_member in ApplicationCable::Connection, then in a channel I broadcast updates when members subscribe/unsubscri

Live comments with model broadcasts + turbo_stream_from

If a feature is fundamentally “live” (comments, activity), I reach for model broadcasts. Rails can broadcast Turbo Stream fragments on after_create_commit, and the UI subscribes with turbo_stream_from. The beauty is that it’s still server-rendered HTM

Turbo Streams + authorization: signed per-user stream name

Never subscribe clients to guessable user-specific streams. Use signed_stream_name so a user can only subscribe to their own broadcasts. This is essential when streaming private notifications.

ActionCable for real-time WebSocket communication

ActionCable integrates WebSockets seamlessly with Rails. Channels handle pub/sub messaging between server and clients. I use ActionCable for chat, notifications, live updates. Channels subscribe clients to streams; broadcasting pushes data to subscrib

Progress indicators for long-running operations

Users need feedback during slow operations like file uploads or complex processing. I combine Turbo Streams with background jobs to show real-time progress. When an operation starts, I enqueue a job that periodically broadcasts progress updates via Ac

Typing indicator via ActionCable + Turbo Streams

Typing indicators can be done without a complex protocol. I broadcast a small turbo stream replace to a typing_indicator target when a user starts typing, and another replace to clear it after a timeout. On the client, a Stimulus controller sends “typ

WebSocket integration with Action Cable

Real-time features like live notifications or collaborative editing require WebSockets. Rails Action Cable provides a WebSocket server, and the @rails/actioncable client connects from React. I create a singleton cable instance and export subscription

ActionCable channel that streams Turbo updates safely

Even with model broadcasts, it’s useful to know how streams map to ActionCable channels. Turbo::StreamsChannel is essentially a channel that streams from a signed stream name. When I need custom behavior, I still follow the same scoping rules: identif

Turbo Stream broadcasts for real-time collaboration

Broadcasting Turbo Streams via Action Cable enables real-time collaborative features without polling. When a model is created, updated, or destroyed, I broadcast the change to all subscribed users using broadcasts_to or manual broadcast_* methods. Sub

Declarative model broadcasts with broadcasts_to (Rails 7)

When I’m on Rails 7+, I like broadcasts_to because it makes realtime behavior obvious in the model. Instead of writing explicit after_create_commit hooks, I declare that a model broadcasts to its parent or to a scope. Then Turbo uses conventional part

Turbo Streams: broadcast from a job for long operations

For long operations (imports, conversions), run work in a job and stream progress updates. The job emits broadcast_update_to so the UI updates live without polling.

Action Cable for real-time WebSocket communication

Action Cable brings WebSocket support to Rails, enabling real-time features like live notifications, collaborative editing, or chat systems. Clients subscribe to channels that broadcast updates when server-side events occur. I use Redis as the pub/sub