Agent skill
rails-expert
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.
Install this agent skill to your Project
npx add-skill https://github.com/Jeffallan/claude-skills/tree/main/skills/rails-expert
Metadata
Additional technical details for this skill
- role
- specialist
- scope
- implementation
- author
- https://github.com/Jeffallan
- domain
- backend
- version
- 1.1.0
- triggers
- Rails, Ruby on Rails, Hotwire, Turbo Frames, Turbo Streams, Action Cable, Active Record, Sidekiq, RSpec Rails
- output format
- code
- related skills
- fullstack-guardian, database-optimizer
SKILL.md
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
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
graphql-architect
Use when designing GraphQL schemas, implementing Apollo Federation, or building real-time subscriptions. Invoke for schema design, resolvers with DataLoader, query optimization, federation directives.
dotnet-core-expert
Use when building .NET 8 applications with minimal APIs, clean architecture, or cloud-native microservices. Invoke for Entity Framework Core, CQRS with MediatR, JWT authentication, AOT compilation.
kubernetes-specialist
Use when deploying or managing Kubernetes workloads. Invoke to create deployment manifests, configure pod security policies, set up service accounts, define network isolation rules, debug pod crashes, analyze resource limits, inspect container logs, or right-size workloads. Use for Helm charts, RBAC policies, NetworkPolicies, storage configuration, performance optimization, GitOps pipelines, and multi-cluster management.
the-fool
Use when challenging ideas, plans, decisions, or proposals using structured critical reasoning. Invoke to play devil's advocate, run a pre-mortem, red team, or audit evidence and assumptions.
spec-miner
Reverse-engineering specialist that extracts specifications from existing codebases. Use when working with legacy or undocumented systems, inherited projects, or old codebases with no documentation. Invoke to map code dependencies, generate API documentation from source, identify undocumented business logic, figure out what code does, or create architecture documentation from implementation. Trigger phrases: reverse engineer, old codebase, no docs, no documentation, figure out how this works, inherited project, legacy analysis, code archaeology, undocumented features.
secure-code-guardian
Use when implementing authentication/authorization, securing user input, or preventing OWASP Top 10 vulnerabilities — including custom security implementations such as hashing passwords with bcrypt/argon2, sanitizing SQL queries with parameterized statements, configuring CORS/CSP headers, validating input with Zod, and setting up JWT tokens. Invoke for authentication, authorization, input validation, encryption, OWASP Top 10 prevention, secure session management, and security hardening. For pre-built OAuth/SSO integrations or standalone security audits, consider a more specialized skill.
Didn't find tool you were looking for?