rails-expert
jeffallan/claude-skills
Rails 7+ specialist for Active Record optimization, Hotwire, Action Cable, Sidekiq, and comprehensive RSpec testing.
What is rails-expert?
Rails Expert is a specialist skill for building Rails 7+ web applications with advanced patterns. It optimizes database queries with includes/eager_load, implements real-time features via Turbo Frames/Streams and Action Cable, configures background job processing with Sidekiq, and writes comprehensive test suites with RSpec. Use when developing Rails applications that require performance optimization, real-time updates, or asynchronous processing.
- Optimize Active Record queries to prevent N+1 problems using includes/eager_load
- Implement Turbo Frames and Turbo Streams for partial page updates without full reloads
- Configure Action Cable for WebSocket-based real-time features
- Set up and manage Sidekiq workers for background job processing with retry logic
- Write comprehensive RSpec test suites targeting >95% code coverage
- Generate Rails resources, migrations, and RESTful controllers with strong parameters
How to install rails-expert
npx skills add https://github.com/jeffallan/claude-skills --skill rails-expert- Rails 7 or later installed
- Ruby 2.7+
- Bundler for dependency management
- RSpec and factory_bot gems for testing
- Sidekiq gem for background jobs (if using job processing)
How to use rails-expert
- 1.Analyze your Rails application requirements and identify models, routes, and real-time needs
- 2.Use the skill to generate resources with `rails generate model` and `rails generate controller`
- 3.Run migrations with `rails db:migrate` and verify schema
- 4.Implement features using provided patterns for Active Record optimization, Turbo, Action Cable, or Sidekiq
- 5.Run `bundle exec rspec` to validate implementation and ensure >95% test coverage
- 6.Audit for N+1 queries and add missing database indexes as needed
Use cases
- Building real-time collaborative features using Turbo Streams and Action Cable
- Optimizing slow database queries in existing Rails applications by adding eager loading
- Setting up background email delivery or data processing jobs with Sidekiq
- Creating dynamic partial page updates with Turbo Frames instead of full page reloads
- Writing test suites for Rails models, controllers, and request specs
- Rails backend developers building Rails 7+ applications
- Full-stack developers implementing Hotwire features
- Teams needing performance optimization and N+1 query prevention
- Developers setting up real-time or background job features
rails-expert FAQ
Use `includes` for most cases—it intelligently chooses between separate queries or a JOIN. Use `eager_load` when you need to filter on the association itself (e.g., `where(authors: { verified: true })`) because it forces a JOIN.
Add `includes(:association)` or `eager_load(:association)` to every collection query that accesses associated data. The skill enforces this pattern in all implementations.
Turbo Frames replace a specific frame's content on page load or link click. Turbo Streams broadcast updates to multiple clients in real-time via Action Cable, ideal for collaborative features.
Use `sidekiq_options retry: N` to set retry attempts. Rescue specific exceptions and log them; avoid re-raising if the error is unrecoverable (e.g., record not found).
The skill targets >95% coverage. Write model specs for validations and associations, request specs for controller actions, and system specs for user workflows.
Full instructions (SKILL.md)
Source of truth, from jeffallan/claude-skills.
name: rails-expert description: Rails 7+ specialist that optimizes Active Record queries with includes/eager_load, implements Turbo Frames and Turbo Streams for partial page updates, configures Action Cable for WebSocket connections, sets up Sidekiq workers for background job processing, and writes comprehensive RSpec test suites. Use when building Rails 7+ web applications with Hotwire, real-time features, or background job processing. Invoke for Active Record optimization, Turbo Frames/Streams, Action Cable, Sidekiq, RSpec Rails. license: MIT metadata: author: https://github.com/Jeffallan version: "1.1.0" domain: backend triggers: Rails, Ruby on Rails, Hotwire, Turbo Frames, Turbo Streams, Action Cable, Active Record, Sidekiq, RSpec Rails role: specialist scope: implementation output-format: code related-skills: fullstack-guardian, database-optimizer
Rails Expert
Core Workflow
- Analyze requirements — Identify models, routes, real-time needs, background jobs
- Scaffold resources —
rails generate model User name:string email:string,rails generate controller Users - Run migrations —
rails db:migrateand verify schema withrails db:schema:dump- If migration fails: inspect
db/schema.rbfor conflicts, rollback withrails db:rollback, fix and retry
- If migration fails: inspect
- Implement — Write controllers, models, add Hotwire (see Reference Guide below)
- Validate —
bundle exec rspecmust pass;bundle exec rubocopfor style- If specs fail: check error output, fix failing examples, re-run with
--format documentationfor detail - If N+1 queries surface during review: add
includes/eager_load(see Common Patterns) and re-run specs
- If specs fail: check error output, fix failing examples, re-run with
- Optimize — Audit for N+1 queries, add missing indexes, add caching
Reference Guide
Load detailed guidance based on context:
| Topic | Reference | Load When |
|---|---|---|
| Hotwire/Turbo | references/hotwire-turbo.md | Turbo Frames, Streams, Stimulus controllers |
| Active Record | references/active-record.md | Models, associations, queries, performance |
| Background Jobs | references/background-jobs.md | Sidekiq, job design, queues, error handling |
| Testing | references/rspec-testing.md | Model/request/system specs, factories |
| API Development | references/api-development.md | API-only mode, serialization, authentication |
Common Patterns
N+1 Prevention with includes/eager_load
# BAD — triggers N+1
posts = Post.all
posts.each { |post| puts post.author.name }
# GOOD — eager load association
posts = Post.includes(:author).all
posts.each { |post| puts post.author.name }
# GOOD — eager_load forces a JOIN (useful when filtering on association)
posts = Post.eager_load(:author).where(authors: { verified: true })
Turbo Frame Setup (partial page update)
<%# app/views/posts/index.html.erb %>
<%= turbo_frame_tag "posts" do %>
<%= render @posts %>
<%= link_to "Load More", posts_path(page: @next_page) %>
<% end %>
<%# app/views/posts/_post.html.erb %>
<%= turbo_frame_tag dom_id(post) do %>
<h2><%= post.title %></h2>
<%= link_to "Edit", edit_post_path(post) %>
<% end %>
# app/controllers/posts_controller.rb
def index
@posts = Post.includes(:author).page(params[:page])
@next_page = @posts.next_page
end
Sidekiq Worker Template
# app/jobs/send_welcome_email_job.rb
class SendWelcomeEmailJob < ApplicationJob
queue_as :default
sidekiq_options retry: 3, dead: false
def perform(user_id)
user = User.find(user_id)
UserMailer.welcome(user).deliver_now
rescue ActiveRecord::RecordNotFound => e
Rails.logger.warn("SendWelcomeEmailJob: user #{user_id} not found — #{e.message}")
# Do not re-raise; record is gone, no point retrying
end
end
# Enqueue from controller or model callback
SendWelcomeEmailJob.perform_later(user.id)
Strong Parameters (controller template)
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
before_action :set_post, only: %i[show edit update destroy]
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post, notice: "Post created."
else
render :new, status: :unprocessable_entity
end
end
private
def set_post
@post = Post.find(params[:id])
end
def post_params
params.require(:post).permit(:title, :body, :published_at)
end
end
Constraints
MUST DO
- Prevent N+1 queries with
includes/eager_loadon every collection query involving associations - Write comprehensive specs targeting >95% coverage
- Use service objects for complex business logic; keep controllers thin
- Add database indexes for every column used in
WHERE,ORDER BY, orJOIN - Offload slow operations to Sidekiq — never run them synchronously in a request cycle
MUST NOT DO
- Skip migrations for schema changes
- Use raw SQL without sanitization (
sanitize_sqlor parameterized queries only) - Expose internal IDs in URLs without consideration
Output Templates
When implementing Rails features, provide:
- Migration file (if schema changes needed)
- Model file with associations and validations
- Controller with RESTful actions and strong parameters
- View files or Hotwire setup
- Spec files for models and requests
- Brief explanation of architectural decisions
Related skills
More from jeffallan/claude-skills and the wider catalog.

react-expert
Senior React specialist for React 18+ components, hooks, Server Components, and production architecture.

react-native-expert
Builds production React Native and Expo apps with optimized navigation, native modules, and cross-platform performance.

rust-engineer
Senior Rust engineer for memory-safe, high-performance code with ownership, async, and trait design.

salesforce-developer
Write and debug Apex, Lightning Web Components, and SOQL queries on Salesforce with governor limit awareness and best practices.

secure-code-guardian
Implement authentication, authorization, input validation, and OWASP Top 10 defenses with secure code patterns.

security-reviewer
Identify vulnerabilities, generate severity-rated audit reports, and provide remediation guidance.