mir-backend-ruby-railslisted
Install: claude install-skill anantbhandarkar/make-it-right
# /mir-backend-ruby-rails · Make It Right (Rails)
Bottom tier of the chain: `mir-backend` (generic gates) → `mir-backend-ruby` (YARV runtime model) → **this** (Rails/ActiveRecord library mechanics). Run the gates first; load the Ruby runtime tier for the GVL, Puma, and fork-safety model; reach for *this* at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. **Runtime-level concerns (GVL, fork-safety, CoW memory, Puma pool sizing, job idempotency) live in `mir-backend-ruby` — not here.**
**Stack assumed:** Rails 7.1+ · ActiveRecord + PostgreSQL · Sidekiq or GoodJob for background jobs. If the project uses a different DB adapter, note divergences (especially around migration concurrency flags) before applying these.
## The Rails footguns AI walks into most
### 1. ActiveRecord N+1 — silent query explosion in loops
N+1 is the most common Rails performance bug: load a collection, then access an association inside a loop, triggering one query per record.
```ruby
# WRONG — 1 query for orders + N queries for users
Order.all.each { |o| puts o.user.email }
# RIGHT — 2 queries total
Order.includes(:user).each { |o| puts o.user.email }
```
**Choose the right eager-loading strategy:**
| Method | SQL shape | Use when |
|---|---|---|
| `preload` | Two separate queries, always | Association is large; you don't need to `WHERE` on it |
| `eager_load` | Single `LEFT OUTER JOIN` | You need to filter/sort by the association (`where("users.role = ?", "admin")`) |
| `in