Community Ruby on Rails Development Best Practices
Comprehensive performance and maintainability optimization guide for Ruby on Rails applications, maintained by Community. Contains 45 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
Writing new Rails controllers, models, or views
Optimizing ActiveRecord queries and database access patterns
api-avoid-jbuilder-hot-paths - Avoid Jbuilder on high-traffic endpoints
8. Background Jobs & Async (LOW-MEDIUM)
job-idempotent-design - Design jobs to be idempotent
job-small-payloads - Pass IDs to jobs, not serialized objects
job-error-handling - Configure retry and error handling for jobs
job-unique-jobs - Prevent duplicate job enqueuing
How to Use
Read individual reference files for detailed explanations and code examples:
Section definitions - Category structure and impact levels
Rule template - Template for adding new rules
Reference Files
File
Description
references/_sections.md
Category definitions and ordering
assets/templates/_template.md
Template for new rules
metadata.json
Version and reference information
1---2name: rails-dev3description: Community Ruby on Rails Development Best Practices4---5# Community Ruby on Rails Development Best Practices67Comprehensive performance and maintainability optimization guide for Ruby on Rails applications, maintained by Community. Contains 45 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.89## When to Apply1011Reference these guidelines when:12- Writing new Rails controllers, models, or views13- Optimizing ActiveRecord queries and database access patterns14- Implementing caching strategies (fragment, Russian doll, low-level)15- Building or refactoring API endpoints16- Adding Turbo Frames and Streams for interactive UIs17- Reviewing code for N+1 queries and security vulnerabilities18- Designing background jobs with Sidekiq or Active Job19- Writing or reviewing database migrations2021## Rule Categories by Priority2223| Priority | Category | Impact | Prefix |24|----------|----------|--------|--------|25| 1 | Database & ActiveRecord | CRITICAL | `db-` |26| 2 | Controllers & Routing | CRITICAL | `ctrl-` |27| 3 | Security | HIGH | `sec-` |28| 4 | Models & Business Logic | HIGH | `model-` |29| 5 | Caching & Performance | HIGH | `cache-` |30| 6 | Views & Frontend | MEDIUM-HIGH | `view-` |31| 7 | API Design | MEDIUM | `api-` |32| 8 | Background Jobs & Async | LOW-MEDIUM | `job-` |3334## Quick Reference3536### 1. Database & ActiveRecord (CRITICAL)3738- [`db-eager-load-associations`](references/db-eager-load-associations.md) - Eager load associations to eliminate N+1 queries39- [`db-add-database-indexes`](references/db-add-database-indexes.md) - Add database indexes on queried columns40- [`db-select-specific-columns`](references/db-select-specific-columns.md) - Select only needed columns41- [`db-batch-processing`](references/db-batch-processing.md) - Use find_each for large dataset iteration42- [`db-avoid-queries-in-loops`](references/db-avoid-queries-in-loops.md) - Avoid database queries inside loops43- [`db-use-scopes`](references/db-use-scopes.md) - Define reusable query scopes on models44- [`db-safe-migrations`](references/db-safe-migrations.md) - Write reversible zero-downtime migrations45- [`db-exists-over-count`](references/db-exists-over-count.md) - Use exists? instead of count for existence checks4647### 2. Controllers & Routing (CRITICAL)4849- [`ctrl-thin-controllers`](references/ctrl-thin-controllers.md) - Keep controllers thin by delegating to models and services50- [`ctrl-strong-params`](references/ctrl-strong-params.md) - Always use strong parameters for mass assignment51- [`ctrl-restful-routes`](references/ctrl-restful-routes.md) - Follow RESTful routing conventions52- [`ctrl-before-action-scoping`](references/ctrl-before-action-scoping.md) - Scope before_action callbacks with only/except53- [`ctrl-respond-to-format`](references/ctrl-respond-to-format.md) - Use respond_to for multi-format responses54- [`ctrl-rescue-from`](references/ctrl-rescue-from.md) - Handle errors with rescue_from in controllers5556### 3. Security (HIGH)5758- [`sec-parameterized-queries`](references/sec-parameterized-queries.md) - Never interpolate user input in SQL59- [`sec-strong-params-whitelist`](references/sec-strong-params-whitelist.md) - Whitelist permitted params, never blacklist60- [`sec-authenticate-before-authorize`](references/sec-authenticate-before-authorize.md) - Authenticate before authorize on every request61- [`sec-csrf-protection`](references/sec-csrf-protection.md) - Enable CSRF protection for all form submissions62- [`sec-scope-queries-to-user`](references/sec-scope-queries-to-user.md) - Scope queries to current user for authorization6364### 4. Models & Business Logic (HIGH)6566- [`model-validate-at-model-level`](references/model-validate-at-model-level.md) - Validate data at the model level67- [`model-avoid-callback-side-effects`](references/model-avoid-callback-side-effects.md) - Avoid side effects in model callbacks68- [`model-use-service-objects`](references/model-use-service-objects.md) - Extract complex logic into service objects69- [`model-scope-over-class-methods`](references/model-scope-over-class-methods.md) - Use scopes instead of class methods for query composition70- [`model-use-enums`](references/model-use-enums.md) - Use enums for finite state fields71- [`model-concerns-for-shared-behavior`](references/model-concerns-for-shared-behavior.md) - Use concerns for shared model behavior72- [`model-query-objects`](references/model-query-objects.md) - Extract complex queries into query objects7374### 5. Caching & Performance (HIGH)7576- [`cache-fragment-caching`](references/cache-fragment-caching.md) - Use fragment caching for expensive view partials77- [`cache-russian-doll`](references/cache-russian-doll.md) - Use Russian doll caching for nested collections78- [`cache-low-level`](references/cache-low-level.md) - Use Rails.cache.fetch for computed data79- [`cache-counter-cache`](references/cache-counter-cache.md) - Use counter caches for association counts80- [`cache-conditional-get`](references/cache-conditional-get.md) - Use conditional GET with stale? for HTTP caching8182### 6. Views & Frontend (MEDIUM-HIGH)8384- [`view-collection-rendering`](references/view-collection-rendering.md) - Use collection rendering instead of loop partials85- [`view-turbo-frames`](references/view-turbo-frames.md) - Use Turbo Frames for partial page updates86- [`view-turbo-streams`](references/view-turbo-streams.md) - Use Turbo Streams for real-time page mutations87- [`view-form-with`](references/view-form-with.md) - Use form_with instead of form_tag or form_for88- [`view-avoid-logic-in-views`](references/view-avoid-logic-in-views.md) - Move display logic to helpers or presenters8990### 7. API Design (MEDIUM)9192- [`api-serializers`](references/api-serializers.md) - Use serializers for consistent JSON responses93- [`api-pagination`](references/api-pagination.md) - Always paginate collection endpoints94- [`api-versioning`](references/api-versioning.md) - Version APIs from day one95- [`api-error-responses`](references/api-error-responses.md) - Return structured error responses96- [`api-avoid-jbuilder-hot-paths`](references/api-avoid-jbuilder-hot-paths.md) - Avoid Jbuilder on high-traffic endpoints9798### 8. Background Jobs & Async (LOW-MEDIUM)99100- [`job-idempotent-design`](references/job-idempotent-design.md) - Design jobs to be idempotent101- [`job-small-payloads`](references/job-small-payloads.md) - Pass IDs to jobs, not serialized objects102- [`job-error-handling`](references/job-error-handling.md) - Configure retry and error handling for jobs103- [`job-unique-jobs`](references/job-unique-jobs.md) - Prevent duplicate job enqueuing104105## How to Use106107Read individual reference files for detailed explanations and code examples:108109- [Section definitions](references/_sections.md) - Category structure and impact levels110- [Rule template](assets/templates/_template.md) - Template for adding new rules111112## Reference Files113114| File | Description |115|------|-------------|116| [references/_sections.md](references/_sections.md) | Category definitions and ordering |117| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |118| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/rails-dev in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Community Ruby on Rails Development Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.