Claude Skills Guide

Claude Code Skills for Ruby on Rails Projects

Ruby on Rails developers benefit significantly from Claude Code’s specialized skills. These tools automate scaffolding, enhance test coverage, optimize database queries, and streamline API integrations. This guide covers practical skills that integrate directly into Rails workflows.

rails-generator: Scaffolding and Code Generation

The rails-generator skill accelerates Rails application setup and CRUD operations. Instead of manually writing models, controllers, and views, invoke this skill to generate functional code structures.

# Generate a complete resource with associations
"Create a Blog app with posts that belong to users and have comments"

This generates migration files, models with relationships, RESTful controllers, and ERB views. The skill understands Rails conventions and produces code following REST principles.

For more complex scenarios, specify custom attributes and validations:

"Generate a Product model with name:string, price:decimal, stock:integer, 
category:references, and validations for presence and uniqueness"

The output includes migration files, model code with associations and validations, controller actions, and corresponding view templates.

rspec-helper: Test-Driven Development

The rspec-helper skill implements test-driven development patterns specific to Rails. It generates comprehensive test suites covering model validations, controller actions, and request specs.

# Generate tests for a User model
"Write RSpec tests for a User model with email validation, password encryption,
and associations to posts and comments"

This produces model specs withshoulda-matchers configurations:

RSpec.describe User, type: :model do
  it { should validate_presence_of(:email) }
  it { should validate_uniqueness_of(:email).case_insensitive }
  it { should have_many(:posts).dependent(:destroy) }
  it { should have_many(:comments).dependent(:destroy) }
  
  context "password encryption" do
    it "creates encrypted password using BCrypt" do
      user = User.create(email: "test@example.com", password: "password123")
      expect(user.encrypted_password).not_to be_empty
    end
  end
end

For controller testing, specify the resource and actions needed:

"Generate controller specs for PostsController with RESTful actions and 
authentication using Devise"

active-record-tuner: Query Optimization

The active-record-tuner skill analyzes and optimizes database queries in Rails applications. It identifies N+1 queries, missing indexes, and inefficient joins.

# Analyze query performance
"Find N+1 queries in the PostsController#index action"

The skill provides specific fixes:

# Before: N+1 query problem
@posts = Post.all
@posts.each do |post|
  puts post.author.name  # Triggers separate query each iteration
end

# After: Eager loading
@posts = Post.includes(:author).all
@posts.each do |post|
  puts post.author.name  # Uses preloaded author data
end

For complex queries, request optimization suggestions:

# Original slow query
Post.where("created_at > ?", 1.week.ago)
    .order(:comments_count)
    .limit(10)

# Optimized with counter cache
Post.where("posts.created_at > ?", 1.week.ago)
    .order("posts.comments_count DESC")
    .limit(10)
    .to_a

The skill also suggests appropriate database indexes based on query patterns:

"Add indexes to improve performance for user dashboard queries showing 
recent orders and pending notifications"

rails-api-builder: REST and GraphQL APIs

The rails-api-builder skill scaffolds API endpoints following Rails best practices. It generates JSON serializers, and supports both REST and GraphQL implementations.

# Generate a REST API for products
"Create a JSON API for Products with CRUD operations, pagination, and 
filtering by category and price range"

The skill produces controller code with proper response formatting:

class Api::ProductsController < ApplicationController
  def index
    products = Product.ransack(params[:q]).result
                      .page(params[:page])
                      .per(params[:per_page] || 25)
    
    render json: {
      data: products.map { |p| ProductSerializer.new(p) },
      meta: {
        current_page: products.current_page,
        total_pages: products.total_pages,
        total_count: products.total_count
      }
    }
  end
  
  def show
    product = Product.find(params[:id])
    render json: ProductSerializer.new(product)
  end
end

For GraphQL integration:

"Generate GraphQL mutations and queries for a Product type with 
connections and filtering support"

migration-manager: Schema Management

The migration-manager skill handles Rails database migrations intelligently. It creates clean migration files, handles schema changes safely, and rollback procedures.

# Generate a migration with proper constraints
"Create a migration to add a status column to Orders with an enum 
and a default value of pending"

The skill outputs properly structured migrations:

class AddStatusToOrders < ActiveRecord::Migration[7.1]
  def change
    add_column :orders, :status, :integer, default: 0, null: false
    add_index :orders, :status
    add_index :orders, [:user_id, :status]
  end
end

For complex schema changes, request data migration strategies:

"Create a migration to split the name column into first_name and last_name,
including a data migration to populate the new columns from existing records"

sidekiq-worker: Background Job Setup

The sidekiq-worker skill configures background processing for Rails applications. It generates worker classes, monitors job queues, and handles error retry logic.

# Create a worker for sending welcome emails
"Generate a Sidekiq worker for sending welcome emails with retry logic
and rate limiting"

Output includes the worker class and configuration:

class WelcomeEmailWorker
  include Sidekiq::Worker
  sidekiq_options retry: 3, queue: :mailers
  
  def perform(user_id)
    user = User.find(user_id)
    UserMailer.welcome(user).deliver_now
  rescue ActiveRecord::RecordNotFound
    # Handle case where user was deleted before job executed
    Rails.logger.warn "User #{user_id} not found for welcome email"
  end
end

Invoke jobs from controllers or models:

# Trigger the worker
"Add code to call the WelcomeEmailWorker after user registration"

Conclusion

These Claude Code skills transform Ruby on Rails development workflows. From generating scaffolded code to optimizing database queries and managing background jobs, each skill targets specific pain points in Rails development. Integrate these skills into your workflow to reduce boilerplate code, improve test coverage, and build reliable Rails applications faster.

Start by invoking one skill for your next Rails task:

"Generate a new scaffold for a Task model with title:string, 
description:text, due_date:date, and status:integer"

Built by theluckystrike — More at zovo.one