Last active
March 18, 2026 06:20
-
-
Save firecall/5f1554259778d43417257ab918272526 to your computer and use it in GitHub Desktop.
Optimised Ruby on Rails coding conventions and guidelines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| description: 'Lean Ruby/Rails Copilot instructions for token efficiency' | |
| applyTo: '**/*.rb' | |
| --- | |
| # Ruby on Rails | |
| ## Must Keep | |
| - Indentation: spaces only, 2 spaces. | |
| - Target Ruby 3.4.7+. | |
| - Do not add `# frozen_string_literal: true`. | |
| - Use double-quoted Ruby strings unless single quotes are required. | |
| - Use snake_case for methods/variables and CamelCase for classes/modules. | |
| - Keep migrations Rails/MySQL compatible. | |
| - Use `JSON`, not `JSONB`. | |
| - Do not set defaults for `BLOB`, `TEXT`, `GEOMETRY`, or `JSON` columns. | |
| - Respect user time zone handling in `application_controller.rb`. | |
| - Format view date/time as `DD/MM/YYYY HH:MM`. | |
| - Shared partials in `app/views/application/`; feature partials stay with features. | |
| ## Code Style | |
| - Prefer Rails helpers/APIs over custom implementations. | |
| - Keep controllers thin; keep business logic in models/services/query objects. | |
| - Keep methods small; use guard clauses to reduce nesting. | |
| - Prefer composition over inheritance. | |
| - Use meaningful names and concise behavior-focused comments. | |
| - Prefer `Rails.logger` over `puts`. | |
| - Prefer `tag` over `content_tag`. | |
| ## Data and Performance | |
| - Use strong parameters for controller writes. | |
| - Prefer scopes/relations over array processing. | |
| - Avoid N+1 queries (`includes` when needed). | |
| - Add DB constraints/indexes for integrity and performance. | |
| ## Structure | |
| - Services: `app/services`. | |
| - Reusable query objects: `app/queries`. | |
| - Custom validators: `app/validators`. | |
| - Authorization: `app/policies`. | |
| ## Views and API | |
| - Keep callbacks minimal and setup-only. | |
| - Keep behavior out of view callbacks/inline JS. | |
| - Build paths with `Rails.root.join(...)`. | |
| - Use Rails predicates (`present?`, `blank?`, `any?`) and safe navigation where appropriate. | |
| - APIs: namespace versions (`/api/v1`), return consistent status/error payloads, paginate large collections. | |
| - Use background jobs for slow/external work. | |
| ## Testing | |
| - Cover models/services/helpers with unit tests. | |
| - Cover end-to-end behavior with request/system tests. | |
| - Stub external APIs and avoid brittle timing assumptions (`sleep`). | |
| - Test background jobs with ActiveJob helpers. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment