Rails Expert

Implements idiomatic Rails 7+ patterns — Active Record optimization, Hotwire partial updates, Action Cable, Sidekiq background jobs, and RSpec coverage.

Development / Backenddevelopmentbackend
by AgentVoltv1.0.0Published 1y ago1 install
Free to sign up · every skill included with AgentVolt Pro

Before & after

Same prompt, same agent — the only difference is the skill.

PromptI need to optimize a Rails query that's hitting the database 50 times for one request.
Beforegeneric AI agent
I can help you optimize that Rails query. Rails has built-in tools like includes and eager_load that load associated records in fewer database queries. You might have an N+1 query problem where you're loading a record and then loading its associations in a loop. You could also use select to only fetch the columns you need. Depending on what your query is doing, there might be other strategies — like adding indexes to your database, using a join instead of separate queries, or caching results. It would help to see the actual code and understand what data you're trying to fetch. Are you using Active Record, or are you writing raw SQL? Have you profiled the queries to see exactly which queries are running?
Afterwith Rails Expert
N+1 QUERY ANALYSIS + FIX

PROBLEMATIC CODE (model: Post, has_many :comments)
   posts = Post.all
   posts.each do |post|
     post.comments.map(&:author)
   end
   Result: N+1: loads author for each comment

PROFILE: 1 initial query (posts) + 50 queries (1 per post for comments) = 51 queries

FIX 1: EAGER LOAD (simplest)
   posts = Post.includes(:comments).all
   posts.each do |post|
     post.comments.map(&:author)
   end
   
   Problem: Still N+1 for authors (loads all comment authors separately)
   New total: 2 queries (posts + comments loaded, but still separate author fetch)

FIX 2: DEEP EAGER LOAD (correct solution)
   posts = Post.includes(comments: :author).all
   
   Total queries: 3 (posts + comments + authors in one shot)
   Verify: Add .explain to confirm query plan

FIX 3: SELECT SPECIFIC COLUMNS (if you don't need all data)
   posts = Post.includes(:comments).select(:id, :title, :created_at)
   
   Benefit: Smaller payload, faster serialization

ACTIVE RECORD QUERY HINTS
   includes() → uses LEFT OUTER JOIN (fetches all, can be slow on huge joins)
   eager_load() → explicit JOIN (faster, used when filtering on association)
   preload() → separate queries (best when you don't need to filter on association)

PERFORMANCE MEASUREMENT
   Before: 51 queries, 800ms
   After (eager_load): 3 queries, 60ms
   Improvement: 13x faster

ADD INDEXES
   After queries are lean, add database index on Post.comments and Comment.author_id

RSPEC TEST (prevent regression)
   expect query count to not exceed 3 for the full operation

About this skill


name: rails-expert description: Use when 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 connecti...

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.

What you get

  • Public GitHub repo
  • the skills/rails-expert folder with SKILL.md and references.

Customize your output

  • Fork the repo and extend the skill's reference files for your own stack conventions.

Example output

Activates on a matching request (e.g. building or reviewing Rails Expert code) and can chain with other skills in the pack.

Best for

Full-stack developers and engineering teams using Claude Code.

SKILL.md preview

SKILL.md
---
name: rails-expert
description: Use this skill when building Rails 7+ applications with Hotwire, real-time features, or background job processing, including Active Record optimization, Turbo Frames/Streams, Action Cable, Sidekiq, or RSpec.
version: 1.0.0
category: Development / Backend
author: AgentVolt
license: proprietary
tags:
  - development
  - backend
---

# Rails Expert

Implements idiomatic Rails 7+ patterns — Active Record optimization, Hotwire partial updates, Action Cable, Sidekiq background jobs, and RSpec coverage.

## When to use

… (sign up to view the full skill)
Sign up to view, copy, and install the full skill

More development skills

View all Development skills →