skills/action-cable/SKILL.md
Setup and use ActionCable for real-time features in Rails applications using WebSockets. Use when implementing real-time updates, live notifications, broadcasting changes, or when the user mentions WebSockets, ActionCable, channels, broadcasting, or Turbo Streams over cable.
npx skillsauth add rolemodel/rolemodel-skills action-cableInstall 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.
ActionCable integrates WebSockets with Rails to enable real-time features. This guide covers the basic setup in this application.
app/channels/application_cable/connection.rb)The connection authenticates and authorizes the WebSocket connection using Devise/Warden.
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
if verified_user = env['warden'].user
verified_user
else
reject_unauthorized_connection
end
end
end
end
app/channels/application_cable/channel.rb)Base channel class for all application channels.
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
app/javascript/initializers/actioncable.js)Initialize ActionCable consumer on the client side.
import * as ActionCable from '@rails/actioncable'
ActionCable.logger.enabled = false
Subscribe to a stream in views:
= turbo_stream_from record
= turbo_stream_from [record, "channel_name"]
Broadcast Turbo Stream updates from controllers or background jobs:
# Append content to a target
Turbo::StreamsChannel.broadcast_append_to(
[record, "channel_name"],
target: "dom_id",
partial: "path/to/partial",
locals: { record: record }
)
# Replace content
Turbo::StreamsChannel.broadcast_replace_to(
[record, "channel_name"],
target: "dom_id",
partial: "path/to/partial",
locals: { record: record }
)
# Remove element
Turbo::StreamsChannel.broadcast_remove_to(
[record, "channel_name"],
target: "dom_id"
)
View:
= turbo_stream_from current_organization, "timers"
#notifications
Controller:
def start_timer
# ... create timer logic ...
Turbo::StreamsChannel.broadcast_append_to(
[current_organization, "timers"],
target: "notifications",
partial: "timers/notification",
locals: { timer: @timer }
)
end
config/cable.yml)development:
adapter: async
test:
adapter: test
production:
adapter: solid_cable
connects_to:
database:
writing: cable
polling_interval: 0.1.seconds
message_retention: 1.day
config/routes.rb)ActionCable is automatically mounted at /cable:
Rails.application.routes.draw do
mount ActionCable.server => '/cable'
end
Enable logging in development:
// app/javascript/initializers/actioncable.js
ActionCable.logger.enabled = true
Check connection status:
const subscription = consumer.subscriptions.create("ExampleChannel", {
connected() {
console.log("Connected to ExampleChannel")
}
})
console.log(subscription)
ApplicationCable::Connectionstream_for instead of stream_from when possible for automatic scopingtesting
Verify what Ruby versions actually exist and install a specific Ruby via rbenv. Use BEFORE asserting that any Ruby version does or doesn't exist (e.g., "Ruby 4.0 isn't out yet", "the latest Ruby is 3.x", "Ruby X.Y.Z doesn't exist"). Also use when the user asks "what's the latest Ruby", "is Ruby X out", "does Ruby X.Y exist", "install Ruby", "switch to Ruby X", "what Ruby is installed", or mentions a specific Ruby version you're unsure about. Claude's training data may be out of date — run `check.sh` first.
development
Trace code through the stack — upward to entry points, downward to data, or laterally across boundaries. Use when the user asks "where does this get called from", "what calls this method", "trace this through the stack", "how does this request flow", "where does this data come from", "follow this through the code", or pastes/selects a piece of code and wants to understand where it fits in the larger system.
tools
Pick the single highest-priority unresolved Sentry issue and hand it off to a fixer skill. Use when triaging Sentry errors, running automated issue triage, or when asked to fix the top Sentry issue in a project.
tools
Find and fix issues from Sentry using MCP. Use when asked to fix Sentry errors, debug production issues, investigate exceptions, or resolve bugs reported in Sentry. Methodically analyzes stack traces, breadcrumbs, traces, and context to identify root causes.