Skip to content
Skillpedia
APIs & servers (backend)12k Β· #11449

rails-expert

What it does

It guides the AI agent to build web applications with Ruby on Rails 7 and newer. It is for developers building Rails apps with live updates and background work.

When to use it

  • βœ“When you are building a Rails 7 app with Hotwire, Turbo Frames, or Turbo Streams.
  • βœ“When you need background jobs with Sidekiq or real-time features with Action Cable.
  • βœ“When Active Record queries cause N+1 problems and need fixing.

Skill link

https://github.com/Jeffallan/claude-skills/blob/main/skills/rails-expert/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/Jeffallan/claude-skills/blob/main/skills/rails-expert/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œBuild a Rails 7 task board with live updates using Turbo Streams and a Sidekiq job for email reminders.”

5 new skills a week. 1 minute to read.

How it works

The agent generates the models and controllers, adds Hotwire for partial page updates, and sets up background jobs. It then runs RSpec and RuboCop to check the work.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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

# 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 de
FAQ

How does it fix slow database queries?

It adds includes or eager_load to remove N+1 queries, and it can add missing indexes.

Which test framework does it use?

It writes RSpec model, request, and system specs.

Does it cover caching?

Yes. It adds caching where it helps speed up pages.

Details

Original description by the author

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.

repo: Jeffallan/claude-skills

Popularity

GitHub stars
12k
Ranking position
#11449
License
MIT
Updated
10/30/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills