.claude/skills/action-cable-patterns/SKILL.md
Implements real-time features with Action Cable and WebSockets. Use when adding live updates, chat features, notifications, real-time dashboards, or when user mentions Action Cable, WebSockets, channels, or real-time. WHEN NOT: Simple HTTP request/response flows, REST APIs, static content, or features that don't need real-time updates.
npx skillsauth add ThibautBaissac/rails_ai_agents action-cable-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Action Cable integrates WebSockets with Rails:
Action Cable is included in Rails by default. Configure it:
# config/cable.yml
development:
adapter: async
test:
adapter: test
production:
adapter: solid_cable # Rails 8 default
# OR
adapter: redis
url: <%= ENV.fetch("REDIS_URL") %>
app/
├── channels/
│ ├── application_cable/
│ │ ├── connection.rb # Authentication
│ │ └── channel.rb # Base channel
│ ├── notifications_channel.rb
│ ├── events_channel.rb
│ └── chat_channel.rb
├── javascript/
│ └── channels/
│ ├── consumer.js
│ ├── notifications_channel.js
│ └── events_channel.js
spec/channels/
├── notifications_channel_spec.rb
└── events_channel_spec.rb
# app/channels/application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
private
def find_verified_user
# Using Rails 8 authentication
if session_token = cookies.signed[:session_token]
if session = Session.find_by(token: session_token)
session.user
else
reject_unauthorized_connection
end
else
reject_unauthorized_connection
end
end
end
end
Four core patterns are available. See channel-patterns.md for full Ruby and JavaScript implementations:
stream_for current_userrejectspeak and typing actions, presence trackingEach pattern follows the same structure:
subscribed — find the resource, check authorization, call stream_forbroadcast_* methods — render partials via ApplicationController.rendererreceived(data) switchBroadcasting can be triggered from services, models, or callbacks. See broadcasting-and-stimulus.md for:
EventsChannel.broadcast_update(event) after persistenceafter_create_commit to trigger channel broadcastsbroadcast_append_to / broadcast_remove_to helpers directly on modelsSee testing.md for full specs. Key conventions:
# Stub connection identity
stub_connection(current_user: user)
# Assert subscription confirmed and streaming
subscribe(event_id: event.id)
expect(subscription).to be_confirmed
expect(subscription).to have_stream_for(event)
# Assert rejection for unauthorized access
expect(subscription).to be_rejected
# Assert broadcast payload
expect {
described_class.notify(user, notification)
}.to have_broadcasted_to(user).with(hash_including(type: "notification"))
development
Creates Turbo Streams, Turbo Frames, and morphing patterns for real-time UI updates. Use when adding real-time updates, partial page rendering, form submissions, or broadcasting. WHEN NOT: For Stimulus JavaScript controllers (see stimulus-patterns skill). For general view conventions (see rules/views.md).
testing
Writes Minitest tests with fixtures following 37signals conventions. Uses Minitest (not RSpec) and fixtures (not factories). Use when writing tests, adding test coverage, or creating fixtures. WHEN NOT: For RSpec or FactoryBot patterns (this project uses Minitest + fixtures exclusively). For test configuration/CI setup (see project docs).
tools
Builds focused, single-purpose Stimulus controllers for progressive enhancement. Use when adding JavaScript behavior, UI interactions, form enhancements, or building reusable client-side components. WHEN NOT: For Turbo Stream/Frame patterns (see turbo-patterns skill). For server-side view logic (see rules/views.md).
testing
Implements the state-as-records-not-booleans pattern for rich state tracking. Use when modeling state changes, replacing boolean flags with record-based state, or when user mentions state records, closures, publications, or toggling state. WHEN NOT: Technical flags like cached/processed (use booleans), concern extraction (use concern-patterns), general model work (use model-patterns).