跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
开发与测试

vanilla-rails

Apply Vanilla Rails (37signals/Basecamp) as the default architecture when writing or changing Rails code: thin controllers, rich models, no service/query/interactor layer unless genuinely justified. Load this skill when creating or editing controllers, models, jobs, concerns, mailers, routes, or form objects; when adding a custom action versus a nested resource; when extracting a service, form, query, or interactor; or when deciding where business logic lives. Also use for Rails reviews and simplification. Do not wait for the user to say "vanilla rails" or "service object". Skip migrations, gem/dependency bumps, CSS/JS/view-only work, credentials, and non-Rails tasks.

iuhoay · 已有 AI 审核记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add iuhoay/skills --skill vanilla-rails

技能说明


name: vanilla-rails description: > Apply Vanilla Rails (37signals/Basecamp) as the default architecture when writing or changing Rails code: thin controllers, rich models, no service/query/interactor layer unless genuinely justified. Load this skill when creating or editing controllers, models, jobs, concerns, mailers, routes, or form objects; when adding a custom action versus a nested resource; when extracting a service, form, query, or interactor; or when deciding where business logic lives. Also use for Rails reviews and simplification. Do not wait for the user to say "vanilla rails" or "service object". Skip migrations, gem/dependency bumps, CSS/JS/view-only work, credentials, and non-Rails tasks. allowed-tools:

  • Grep
  • Glob
  • Read
  • Task

Vanilla Rails

Default architecture when writing Rails, from the Vanilla Rails philosophy of 37signals/Basecamp. Apply it while implementing — do not wait for a review command or for the user to name the philosophy.

Based on Fizzy

This skill is informed by Fizzy - a production Rails application from 37signals.

Key Fizzy patterns:

  • Controllers call Active Record directly: @board.update!(board_params), @card.comments.create!(comment_params)
  • Models composed of concerns: include Closeable, Golden, Postponable, Watchable
  • State tracked with dedicated models: has_one :closure, has_one :goldness
  • No app/services/ directory
  • Complex multi-step processes use plain objects or ActiveRecord models with state

Quick Start

Vanilla Rails embraces Rails's built-in patterns and avoids premature abstraction:

Core Philosophy: Thin controllers that directly invoke a rich domain model. No service layers or other artifacts unless genuinely justified.

┌─────────────────────────────────────────┐
│              CONTROLLERS                 │
│         (Thin - HTTP concerns only)      │
└─────────────────────────────────────────┘
                    ↓
┌─────────────────────────────────────────┐
│               MODELS                     │
│    (Rich - Business logic lives here)    │
└─────────────────────────────────────────┘
                    ↓
┌─────────────────────────────────────────┐
│          ACTIVE RECORD / DATABASE        │
└─────────────────────────────────────────┘

Core Rule: Don't add layers beyond what Rails provides unless you have a clear, justified reason.

Default constraint

This skill is the house style for Rails work, not an optional review lens. When loaded during implementation, apply the principles below while writing code. Do not ask which review command to run.

Do:

  • Put domain logic on the model, or a namespaced concern of that model
  • Keep controllers to params + one model call
  • Prefer a new nested resource over a custom controller action
  • Keep jobs and mailers shallow: _later enqueues, _now does the work on the model

Do not introduce app/services/, app/queries/, interactors, managers, or handlers unless the bar in When Services Are Actually OK is met — and say so in the change.

Skip this overlay for migrations, gem/dependency bumps, CSS/JS, view-only markup, credentials, and anything that is not Rails application code.

Explicit commands

Use these only when the user asks to review, analyze, or plan a simplification — not as the default response to Rails implementation:

  1. Review code changes - /vanilla-rails:review
  2. Analyze codebase - /vanilla-rails:analyze
  3. Plan simplification - /vanilla-rails:simplify [goal]

Core Principles

The Three Rules

  1. Thin Controllers - Controllers only parse params and invoke model methods
  2. Rich Domain Model - Business logic belongs in models
  3. No Premature Abstraction - Don't create service layers by default

Common Anti-Patterns

Anti-PatternExampleFix
Fat service100-line service with domain logicMove logic to model
Anemic modelModel with only attributes and associationsAdd business methods
Controller as orchestratorController calling multiple servicesCall rich model methods
Premature serviceSimple CRUD wrapped in serviceUse plain Active Record
Service explosionDoSomethingService for every actionMost should be model methods

See Anti-Patterns Reference for complete list.

When Services Are Actually OK

Services are justified when:

  • Coordinating multiple models (orchestration, not domain logic)
  • External API interactions
  • Multi-step workflows with transaction boundaries
  • Operations that don't naturally belong to any single model

Fizzy uses plain objects for this:

# Multi-step signup with ActiveModel::Model
class Signup
  include ActiveModel::Model

  validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }
  validates :full_name, presence: true

  def create_identity
    @identity = Identity.find_or_create_by!(email_address: email_address)
    @identity.send_magic_link(for: :sign_up)
  end

  def complete
    # Complex account creation with rollback handling
  end
end

Fizzy uses ActiveRecord models for stateful operations:

# Stateful import with status tracking
class Account::Import < ApplicationRecord
  enum :status, %w[ pending processing completed failed ].index_by(&:itself), default: :pending

  def process(start: nil, callback: nil)
    processing!
    # Import logic with ZIP file handling
    mark_completed
  rescue => e
    mark_as_failed
    raise e
  end
end

Style Preferences

Conditional Returns

Prefer expanded conditionals over guard clauses (unless returning early at method start for non-trivial bodies).

# Bad - Guard clause
def todos_for_new_group
  ids = params.require(:todolist)[:todo_ids]
  return [] unless ids
  @bucket.recordings.todos.find(ids.split(","))
end

#
阅读完整来源 ↗