rails-expert

jeffallan/claude-skills · updated Apr 8, 2026

$npx skills add https://github.com/jeffallan/claude-skills --skill rails-expert
0 commentsdiscussion
summary

Rails 7+ specialist optimizing queries, implementing Hotwire real-time features, and background job processing.

  • Covers Active Record query optimization with includes / eager_load to prevent N+1 queries, plus database indexing strategies
  • Implements Turbo Frames and Turbo Streams for partial page updates, and Action Cable configuration for WebSocket-based real-time features
  • Provides Sidekiq worker templates for background job processing with retry logic and error handling
  • Includes R
skill.md

Rails Expert

Core Workflow

  1. Analyze requirements — Identify models, routes, real-time needs, background jobs
  2. Scaffold resourcesrails generate model User name:string email:string, rails generate controller Users
  3. Run migrationsrails 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. Validatebundle 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

# 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_load on 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, or JOIN
  • 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_sql or parameterized queries only)
  • Expose internal IDs in URLs without consideration

Output Templates

When implementing Rails features, provide:

  1. Migration file (if schema changes needed)
  2. Model file with associations and validations
  3. Controller with RESTful actions and strong parameters
  4. View files or Hotwire setup
  5. Spec files for models and requests
  6. Brief explanation of architectural decisions

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.544 reviews
  • Xiao Bhatia· Dec 28, 2024

    Solid pick for teams standardizing on skills: rails-expert is focused, and the summary matches what you get after install.

  • Amina Thomas· Dec 28, 2024

    Keeps context tight: rails-expert is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Chen Verma· Dec 16, 2024

    We added rails-expert from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Pratham Ware· Dec 12, 2024

    Registry listing for rails-expert matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Chen Rahman· Nov 19, 2024

    rails-expert has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Anaya Abebe· Nov 19, 2024

    I recommend rails-expert for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Isabella Chawla· Nov 7, 2024

    Useful defaults in rails-expert — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Sakshi Patil· Nov 3, 2024

    rails-expert reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Amina Iyer· Nov 3, 2024

    rails-expert fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Kofi Mehta· Oct 26, 2024

    rails-expert has been reliable in day-to-day use. Documentation quality is above average for community skills.

showing 1-10 of 44

1 / 5