diff --git a/rails/ai-rules/rules/controllers.md b/rails/ai-rules/rules/controllers.md index 7968e0f5..7978012d 100644 --- a/rails/ai-rules/rules/controllers.md +++ b/rails/ai-rules/rules/controllers.md @@ -1,9 +1,8 @@ # Controllers - Controllers handle HTTP only: receive request, delegate to model, return response. -- Actions should not exceed 10 lines (excluding strong params). Longer actions often signal business logic that belongs in a model or PORO. +- Avoid long actions, since they often signal business logic that belongs in a model or PORO. - Maximum one instance variable per action. - No business logic, calculations, email sending, or multi-object operations in controllers. -- Always use strong parameters. Never `params.permit!`. - Return `status: :unprocessable_entity` on failed form renders (required by Turbo). - Prefer RESTful routes. Custom verb actions (e.g., post "activate") usually mean a missing noun/resource (e.g., resource :trial, only: [:create]). diff --git a/rails/ai-rules/rules/database.md b/rails/ai-rules/rules/database.md index bb13fc44..9f730eea 100644 --- a/rails/ai-rules/rules/database.md +++ b/rails/ai-rules/rules/database.md @@ -1,9 +1,8 @@ # Database & Migrations - Always use the `rails generate migration` command to create migration files. -- Migrations must be reversible. -- Add `null: false` and database-level defaults where appropriate. - Use `text` over `string` if length varies significantly. +- Add `null: false` and database-level defaults where appropriate. - Wrap multi-record operations in transactions. Use `save!` (bang) inside transactions. - Keep scopes as one-liners. Complex queries belong in search/query objects. - Never use `Post.all` without pagination. diff --git a/rails/ai-rules/rules/models.md b/rails/ai-rules/rules/models.md index 71a8716f..b8f70c37 100644 --- a/rails/ai-rules/rules/models.md +++ b/rails/ai-rules/rules/models.md @@ -4,8 +4,7 @@ - Name classes after domain nouns, not actions. No `*Service`, `*Manager`, `*Handler` suffixes. - Use `ActiveModel::Model` for POROs that need validation or form integration. - Replace `.call` / `.perform` with domain verbs: `#save`, `#complete`, `#submit`, `#deliver`. -- Look to identify domain models that can be extracted when an existing - model exceeds: 200 lines, 15 public methods, or 7 private methods. +- Look to identify domain models that can be extracted when an existing model is large. - Callbacks only for data integrity (normalise fields, set defaults). Never for emails, payments, or external systems. - Prefer composition over inheritance. Extract behaviour into small, focused objects. -- Avoid feature envy, long parameter lists (max 3 args), case statements on type, and mixin abuse. +- Avoid feature envy, long parameter lists, case statements on type, and mixin abuse. diff --git a/rails/ai-rules/rules/testing.md b/rails/ai-rules/rules/testing.md index 3ecf75fd..7f3c2538 100644 --- a/rails/ai-rules/rules/testing.md +++ b/rails/ai-rules/rules/testing.md @@ -11,5 +11,4 @@ - Factories: only required attributes with sensible defaults. Start in `spec/factories.rb`. - Shoulda Matchers for validations and associations. - WebMock blocks all external HTTP in tests — always stub external requests. -- One `expect` per `it` block. Max 2 levels of context nesting. - Never test private methods directly. Never stub the system under test.