← Prompts
Reference Copilot Instructions Collection

Ruby on Rails coding conventions and guidelines

Ruby on Rails coding conventions and guidelines

# Ruby on Rails

## General Guidelines

- Follow the RuboCop Style Guide and use tools like `rubocop`, `standardrb`, or `rufo` for consistent formatting.
- Use snake_case for variables/methods and CamelCase for classes/modules.
- Keep methods short and focused; use early returns, guard clauses, and private methods to reduce complexity.
- Favor meaningful names over short or generic ones.
- Comment only when necessary — avoid explaining the obvious.
- Apply the Single Responsibility Principle to classes, methods, and modules.
- Prefer composition over inheritance; extract reusable logic into modules or services.
- Keep controllers thin — move business logic into models, services, or command/query objects.
- Apply the “fat model, skinny controller” pattern thoughtfully and with clean abstractions.
- Extract business logic into service objects for reusability and testability.
- Use partials or view components to reduce duplication and simplify views.
- Use `unless` for negative conditions, but avoid it with `else` for clarity.
- Avoid deeply nested conditionals — favor guard clauses and method extractions.
- Use safe navigation (`&.`) instead of multiple `nil` checks.
- Prefer `.present?`, `.blank?`, and `.any?` over manual nil/empty checks.
- Follow RESTful conventions in routing and controller actions.
- Use Rails generators to scaffold resources consistently.
- Use strong parameters to whitelist attributes securely.
- Prefer enums and typed attributes for better model clarity and validations.
- Keep migrations database-agnostic; avoid raw SQL when possible.
- Always add indexes for foreign keys and frequently queried columns.

Sign in to view the full prompt.

Sign In

Classification

Reference Documentation, cheatsheets, setup guides
Scope Project
This codebase
Manual Manually placed / Persistent