/reactree-rails-dev:rails-conventionsfrom reactree-rails-dev
Guides Ruby on Rails conventions, design patterns, and idiomatic code standards. Helps with writing controllers/models/services, choosing patterns (Service, Form, Query objects), and reviewing code for conventions.
Ships in reactree-rails-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Authoritative guidance on Ruby on Rails conventions and design patterns.
What are you building?
│
├─ Business logic spanning multiple models?
│ └─ Service Object (app/services/)
│
├─ Form spanning multiple models or complex validation?
│ └─ Form Object (app/forms/)
│
├─ Complex queries with multiple conditions?
│ └─ Query Object (app/queries/)
│
├─ View logic becoming complex?
│ └─ Decorator/Presenter (app/decorators/, app/presenters/)
│
├─ Truly shared behavior across 3+ unrelated models?
│ └─ Concern (app/models/concerns/)
│
└─ Simple single-model operation?
└─ Keep in model/controller (no extra pattern)
NEVER use concerns for 1-2 models:
# WRONG - Concern for single model
module UserHelpers
def full_name
"#{first_name} #{last_name}"
end
end
# RIGHT - Keep in model if only used there
class User < ApplicationRecord
def full_name
"#{first_name} #{last_name}"
end
end
NEVER put business logic in controllers:
# WRONG - Fat controller
def create
@order = Order.new(order_params)
@order.calculate_tax
@order.apply_discount(params[:coupon])
@order.reserve_inventory
PaymentGateway.charge(@order.total)
@order.save
end
# RIGHT - Delegate to service
def create
@order = CreateOrderService.call(current_user, order_params)
redirect_to @order
end
NEVER use unless with else:
# WRONG
unless user.admin?
deny_access
else
grant_access
end
# RIGHT
if user.admin?
grant_access
else
deny_access
end
NEVER exceed 4 parameters without keyword arguments:
# WRONG
def create_user(email, password, name, role, department, manager_id)
# RIGHT - Use keyword arguments
def create_user(email:, password:, name:, role:, department:, manager_id:)
# RIGHT - Use parameter object for many params
def create_user(user_params)
NEVER monkey patch in application code:
# WRONG - Monkey patching String
class String
def to_slug
downcase.gsub(' ', '-')
end
end
# RIGHT - Create utility method
module StringUtils
def self.slugify(text)
text.downcase.gsub(' ', '-')
end
end
| Type | Location | Max Lines | Purpose |
|---|---|---|---|
| Models | app/models/ | 200 | Associations, validations, scopes |
| Controllers | app/controllers/ | 100 | REST actions, request handling |
| Services | app/services/ | 150 | Business logic, orchestration |
| Forms | app/forms/ | 100 | Multi-model forms, complex validation |
| Queries | app/queries/ | 100 | Complex reusable queries |
| Presenters | app/presenters/ | 100 | View-specific logic |
| Jobs | app/jobs/ | 50 | Background processing |
| Mailers | app/mailers/ | 50 | Email generation |
classes: "PascalCase" # UserProfile, OrderService
methods: "snake_case" # create_order, find_by_email
predicates: "end with ?" # active?, valid?, admin?
dangerous_methods: "end with !" # save!, destroy!, update!
constants: "SCREAMING_SNAKE" # MAX_RETRIES, DEFAULT_LIMIT
private_methods: "descriptive" # NOT underscore prefix
| Pattern | Example |
|---|---|
| Guard clauses | return unless user.active? |
| Safe navigation | user&.profile&.avatar |
| Keyword arguments (2+ params) | def call(user:, params:) |
Struct/Data for value objects | User = Data.define(:id, :name) |
frozen_string_literal: true | At top of every file |
| Explicit returns for clarity | return Result.failure(errors) |
| Anti-Pattern | Why |
|---|---|
unless with else | Confusing logic |
| Nested ternaries | Hard to read |
and/or for control flow | Unexpected precedence |
| Monkey patching | Maintenance nightmare |
| More than 15 lines/method | Single responsibility |
class CreateOrderService
def initialize(user:, params:)
@user = user
@params = params
end
def call
validate_params
order = build_order
process_payment
send_confirmation
Result.success(order)
rescue PaymentError => e
Result.failure(e.message)
end
private
attr_reader :user, :params
def validate_params
# ...
end
def build_order
# ...
end
end
Always implement bottom-up (dependencies first):
1. Database migrations
2. Models (foundation)
3. Services (business logic)
4. Components (presentation wrappers)
5. Controllers (orchestration)
6. Views (final layer)
7. Tests (verify everything)
Before shipping any code:
Before Writing Any Code:
# Check existing patterns
ls app/services/
ls app/forms/ 2>/dev/null
# Check naming conventions
head -30 $(find app/services -name '*.rb' | head -1)
# Check dependencies
grep -v '^#' Gemfile | grep -v '^$'
Detailed patterns and examples in references/:
controllers.md - RESTful, API, Hotwire, nested resource controllersdesign-patterns.md - Form objects, decorators, presenters, repositories, DTOsbackground-jobs-mailers.md - ActiveJob, Sidekiq, mailers, Action Cablemodern-rails.md - Rails 7.1+/8.0+ features, Ruby 3.3+, concerns, visibilityWhat SKILL.md sets; muted values are Claude Code's defaults
26 skills in this plugin
/accessibility-patternsAccessibility PatternsWCAG 2.2 Level AA compliance for Rails/ViewComponent/Hotwire. Use when: (1) Building interactive widgets, (2) Handling form validation errors, (3) Adding dynamic content with Turbo Streams, (4) Auditing existing components. Trigger keywords: accessibility, a11y, WCAG, ARIA, screen reader, keyboard, focus, contrast/action-cable-patternsAction Cable & WebSocket PatternsReal-time WebSocket features with Action Cable in Rails. Use when: (1) Building real-time chat, (2) Live notifications/presence, (3) Broadcasting model updates, (4) WebSocket authorization. Trigger keywords: Action Cable, WebSocket, real-time, channels, broadcasting, stream, subscriptions, presence, cable/activerecord-patternsActiveRecord Query PatternsComplete guide to ActiveRecord query optimization, associations, scopes, and PostgreSQL-specific patterns. Use when: (1) Writing database queries, (2) Designing model associations, (3) Creating migrations, (4) Optimizing query performance, (5) Debugging N+1 queries and GROUP BY errors. Trigger keywords: database, models, associations, validations, queries, ActiveRecord, scopes, migrations, N+1, PostgreSQL, indexes, eager loading/api-development-patternsAPI Development PatternsComprehensive guide to building production-ready REST APIs in Rails with serialization, authentication, versioning, rate limiting, and testing. Trigger keywords: REST API, JSON, serialization, versioning, authentication, JWT, rate limiting, API controllers, request specs, API testing, endpoints, responses/codebase-inspectionCodebase Inspection ProtocolMandatory inspection before writing any Rails code. Use when: (1) Starting ANY implementation task, (2) Making architectural decisions, (3) Suggesting patterns or conventions, (4) Creating new files/classes. Core rule: Never plan without file path citations. Trigger keywords: analyze, inspect, patterns, conventions, codebase, discover, structure, dependencies, existing, before/code-quality-gatesCode Quality GatesExpert decision trees for Solargraph, Sorbet, and Rubocop validation in Rails. Use when: (1) Choosing which quality tool for a task, (2) Debugging type errors or lint failures, (3) Setting up validation pipelines, (4) Deciding strictness levels. Trigger keywords: quality gates, validation, solargraph, sorbet, rubocop, type checking, linting, code quality, static analysis, type safety, srb tcnpx claudepluginhub kaakati/rails-enterprise-dev --plugin reactree-rails-devOther plugins' skills for the same job