Command Palette

Search for a command to run...

Back to skills
skill № 96635

ruby-rails

Use when the user asks about Ruby on Rails, ActiveRecord callbacks getting out of hand, service objects, Rails API mode, Active Job / Solid Queue, N+1 with…

FreeNo executable scripts
j4flmaoby j4flmao★ 47 GitHub stars

Install ruby-rails in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

Ruby on Rails

Purpose

Build Rails applications with clean MVC separation, service objects, ActiveRecord optimization, API mode conventions, Sidekiq background jobs, and RSpec testing patterns.

Agent Protocol

Trigger

User request includes: Rails, Ruby on Rails, Rails API, ActiveRecord, Rails controller, Rails model, Rails service, Rails job, Rails spec, Rails migration.

Input Context

  • Rails version (7.0+, 7.1+)
  • Ruby version (3.1+, 3.2+, 3.3+)
  • Database (PostgreSQL, MySQL, SQLite)
  • Mode (API-only, full MVC)
  • Auth (Devise, JWT, OAuth)
  • Background jobs (Sidekiq, GoodJob, Solid Queue)

Output Artifact

Controller, model, service object, job class, migration, RSpec test.

Response Format

Produce artifact directly. No preamble, no postamble, no explanations.

Completion Criteria

  • Controller delegates to service objects
  • ActiveRecord model with scopes, validations, associations
  • Service object encapsulates business logic
  • Background job with retry configuration
  • Request spec covers CRUD with JSON
  • Migration with proper indexes

Max Response Length

4096 tokens

Architecture Decision Trees

Service Objects vs PORO Models vs Concerns

Criterion Service Object Fat Model Concern
Business logic location app/services/ app/models/ app/concerns/
Testability Easy (isolated) Moderate (needs DB) Moderate
Reusability High (injectable) Low (AR callbacks) Medium (mixed into models)
Complexity per unit Low High (grows unbound) Medium
Rails conventions No (manual) Yes (default) Yes (Rails 4+)

Decision: Complex business rules → Service Object. Simple validations/scopes → Model. Cross-model behavior → Concern.

ActiveRecord vs ActiveRecord::Base vs Sequel

Criterion ActiveRecord Sequel ROM.rb
Rails integration Native Adapter Adapter
Performance Moderate High High
Query interface Rich DSL Sequel DSL Relation-based
Associations Declarative Declarative Explicit
Migration system Built-in Built-in Standalone

Decision: Rails project → ActiveRecord. Heavy data pipeline → Sequel. Hexagonal/clean arch → ROM.rb.

Workflow

Step 1: Rails API Setup

rails new my_api --api --database=postgresql --skip-test
cd my_api

Step 2: Directory Conventions (API Mode)

app/
  controllers/
    application_controller.rb
    api/
      v1/
        users_controller.rb
        orders_controller.rb
  models/
    user.rb
    order.rb
  services/
    users/
      create_service.rb
      update_service.rb
    orders/
      place_order_service.rb
  serializers/
    user_serializer.rb
    order_serializer.rb
  jobs/
    process_order_job.rb
  policies/
    user_policy.rb
config/
  routes.rb
spec/
  requests/
    users_spec.rb
  services/
    users/
      create_service_spec.rb

Step 3: Routes

# config/routes.rb
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :users, only: [:index, :show, :create, :update, :destroy]
      resources :orders, only: [:index, :show, :create]
    end
  end
end

Step 4: ActiveRecord Model

# app/models/user.rb
class User < ApplicationRecord
  # Enums
  enum :role, { user: 0, admin: 1, moderator: 2 }, default: :user

  # Validations
  validates :email, presence: true, uniqueness: { case_sensitive: false },
                    format: { with: URI::MailTo::EMAIL_REGEXP }
  validates :name, presence: true, length: { minimum: 2, maximum: 100 }

  # Scopes
  scope :active, -> { where(active: true) }
  scope :by_role, ->(role) { where(role: role) }
  scope :recent, -> { order(created_at: :desc) }
  scope :search, ->(query) {
    where('name ILIKE :q OR email ILIKE :q', q: "%#{sanitize_sql_like(query)}%")
  }

  # Associations
  has_many :orders, dependent: :destroy

  # Callbacks
  after_create :send_welcome_email

  private

  def send_welcome_email
    UserMailer.welcome(self).deliver_later
  end
end

# db/migrate/xxxx_create_users.rb
class CreateUsers < ActiveRecord::Migration[7.1]
  def change
    create_table :users, id: :uuid do |t|
      t.string :name, null: false
      t.string :email, null: false
      t.integer :role, default: 0, null: false
      t.boolean :active, default: true, null: false
      t.timestamps
    end
    add_index :users, :email, unique: true
    add_index :users, :role
    add_index :users, [:active, :role]
  end
end

Step 5: Serializer

# app/serializers/user_serializer.rb
class UserSerializer
  include JSONAPI::Serializer

  attributes :name, :email, :role, :active
  attribute :created_at do |user|
    user.created_at.iso8601
  end
  has_many :orders, serializer: OrderSerializer
end

Step 6: Service Object

# app/services/users/create_service.rb
module Users
  class CreateService < App
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

  • references/rails-active-record.md
  • references/rails-api-conventions.md
  • references/rails-api-design.md
  • references/rails-background-jobs.md
  • references/rails-performance-tuning.md
  • references/rails-performance.md
  • references/rails-security.md
  • references/rails-testing.md

FAQ

What does the ruby-rails skill do?

Use when the user asks about Ruby on Rails, ActiveRecord callbacks getting out of hand, service objects, Rails API mode, Active Job / Solid Queue, N+1 with includes or RSpec. Produces Rails 8 code with thin models and controllers. Not for Ruby outside Rails or Phoenix (use backend-elixir).

How do I install the ruby-rails skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the ruby-rails skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare ruby-rails with