# Rails Expert

Rails 7+ specialist that optimizes Active Record queries with includes/eager_load...

- Repository: https://github.com/Jeffallan/claude-skills (12164 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add Jeffallan/claude-skills --skill rails-expert -g -a claude-code -y`
Codex: `npx skills add Jeffallan/claude-skills --skill rails-expert -g -a codex -y`
Cursor: `npx skills add Jeffallan/claude-skills --skill rails-expert -g -a cursor -y`
Gemini CLI: `npx skills add Jeffallan/claude-skills --skill rails-expert -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add Jeffallan/claude-skills`

## 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.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Rails Expert

## Core Workflow

1. **Analyze requirements**, Identify models, routes, real-time needs, background jobs
2. **Scaffold resources**, `rails generate model User name:string email:string`, `rails generate controller Users`
3. **Run migrations**, `rails db:migrate` and verify schema with `rails db:schema:dump`
   - If migration fails: inspect `db/schema.rb` for conflicts, rollback with `rails db:rollback`, fix and retry
4. **Implement**, Write controllers, models, add Hotwire (see Reference Guide below)
5. **Validate**, `bundle exec rspec` must pass; `bundle exec rubocop` for style
   - If specs fail: check error output, fix failing examples, re-run with `--format documentation` for detail
   - If N+1 queries surface during review: add `includes`/`eager_load` (see Common Patterns) and re-run specs
6. **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

```ruby
# 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)

The rest: https://github.com/Jeffallan/claude-skills/blob/HEAD/skills/rails-expert/SKILL.md
