anantbhandarkar/make-it-right/mir-backend-ruby-rails
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
Checking that the SKILL.md file is still in the repository.
Make It Right (Rails module). Ruby on Rails 8.1 specific reliability augmentation. Use alongside mir-backend and mir-backend-ruby when the target stack is Rails — carries the mechanical footguns the framework-agnostic skills deliberately omit: ActiveRecord N+1 and eager-loading strategies, params.expect / strong parameters and mass-assignment safety, callback side-effect timing (after_commit vs after_save) and jobs enqueued inside transactions, transaction semantics and nested transactions, migration safety on populated tables (the #1 Rails production incident class), connection pool sizing across the Rails 8 primary/cache/queue/cable databases, and the Rails security defaults and Active Storage advisories. TRIGGER only when the Ruby backend is Rails — building, reviewing, or debugging a Rails controller, model, concern, migration, Active Storage attachment, or background job that uses ActiveRecord. Always loads TOGETHER WITH mir-backend (the gates) and mir-backend-ruby (YARV runtime: GVL, Ractors, YJIT, Puma fork-safety, CoW memory, Rack/Puma/Bundler advisories); this module only adds Rails/ActiveRecord library mechanics — send Ruby-runtime, Puma, Rack or gem-supply-chain questions to mir-backend-ruby instead. SKIP for Sinatra, Hanami, pure Rack apps, or non-Ruby runtimes.
Install
npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-ruby-railsSKILL.md
The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-ruby-rails.
/mir-backend-ruby-rails · Make It Right (Rails)
Bottom tier of the chain: mir-backend (generic gates) → mir-backend-ruby (YARV runtime + Rack/Puma/Bundler) → 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, Ractors, YJIT, fork-safety, CoW memory, Rack and Puma CVEs, gem supply chain) live in `mir-backend-ruby` — not here.
Stack assumed: Rails 8.1 · ActiveRecord + PostgreSQL · Solid Queue (the Rails 8 default) or Sidekiq/GoodJob for background jobs. Current release is 8.1.3.1 (29 Jul 2026); 8.0.5.1 is the security-only 8.0 line (8.0 bugfix support ended 7 May 2026); 8.2 exists only on edge and is not released — anything below marked "8.2" is not something you can ship today. Rails 8.1's gemspec requires Ruby >= 3.2.0. Verified against rubyonrails.org and rubygems.org on 13 Aug 2026. If the project uses a different DB adapter, note divergences (especially around migration concurrency flags) before applying these.
What changed in Rails 8.0 / 8.1 (check before trusting older Rails advice)
| Change | Version | What it means for your code | |
|---|---|---|---|
params.expect | 8.0 | The current recommended strong-parameters API. require(...).permit(...) still works but turns malformed input into 500s — see §2 | |
| Solid Queue / Solid Cache / Solid Cable are the defaults for new apps | 8.0 | Jobs, cache and Action Cable are now database-backed. Every one is another connection pool and another write path on your DB — see §6 | |
bin/rails generate authentication | 8.0 | Sessions table + has_secure_password + rate_limit. Authentication only — no registration, confirmation, MFA, lockout, or authorization — see Security | |
rate_limit to:, within: on Action Controller | 8.0 | Built-in throttling; the auth generator ships one on SessionsController#create | |
enqueue_after_transaction_commit symbol values and the app-wide config both removed | 8.1 | :always/:never/:default now raise; config.active_job.enqueue_after_transaction_commit is gone from 8.1 — set it per job class. Default is still OFF — see §3 | |
Built-in sidekiq Active Job adapter deprecated; sucker_punch adapter removed | 8.1 | Switch to the adapter shipped by the sidekiq gem (requires sidekiq ≥ 7.3.3) | |
include ActiveJob::Continuable | 8.1 | Long jobs resume from the last completed step after a restart. Steps must still be idempotent — a continuation saves the cursor, not the side effect | |
Rails.event.notify (structured event reporting) | 8.1 | A second place application data leaves the process. config.filter_parameters does not filter it | |
Associations can be marked deprecated: true (:warn / :raise / :notify) | 8.1 | Use :raise in CI to make removal safe | |
Order-dependent finders without an explicit order deprecated; insert_all/upsert_all with unpersisted records deprecated; signed_id_verifier_secret deprecated | 8.1 | Add explicit .order(...) before .first/.last; these become errors later | |
Leading-bracket param parsing, ; query separators, multi-path routes removed | 8.1 | Old query-string handling and get ["/a", "/b"] => ... routes fail |
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.
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")) | |
includes | Picks preload or eager_load automatically based on whether a references or where clause touches the association | Default — let Rails decide unless behavior is surprising |
- Bullet gem (
gem "bullet") detects N+1 and unused eager loads in development/test — add it toGemfileand enable inconfig/environments/development.rb. - `strict_loading`:
Order.strict_loading.allraisesActiveRecord::StrictLoadingViolationErroron any lazy association access — zero-overhead enforcement in CI.
Turning this on across an existing app raises everywhere at once. Stage it with config.active_record.action_on_strict_loading_violation = :log, fix what appears in the logs, then flip to :raise.
2. Mass assignment — params.expect is the current API, permit! is never the answer
Rails prevents assigning arbitrary request params to models. Rails 8 replaced the `require`/`permit` pair with `params.expect`, and AI still writes the old form (or permit!).
Why it matters beyond style: expect validates the shape, so parameter tampering raises ActionController::ParameterMissing and returns 400, where require/permit raises NoMethodError and returns 500 with a backtrace. RuboCop's Rails/StrongParametersExpect will flag the old form.
- Arrays of hashes need double brackets.
params.expect(post: [:title, categories: [[:name]]]). A single bracket means "an array of scalars" and the nested hashes are silently dropped. - `accepts_nested_attributes_for` is where this bites. Indexed nested-attribute hashes get filtered out with no error — the record just saves without the children and a validation fails somewhere unrelated. Write
line_items_attributes: [[:id, :description, :quantity, :_destroy]]. - Never permit
:id,:user_id,:tenant_id,:account_id,:role,:admin,:stripe_customer_id. Ownership columns are set from the session, never from params. - Use distinct parameter shapes for
createvsupdatewhen a field is only settable at creation.
3. Callbacks and job enqueues — external effects belong after the transaction commits
ActiveRecord callbacks (after_save, after_create, after_update) fire inside the wrapping database transaction. If the transaction later rolls back, the callback already ran — but the DB row was never committed.
Rule: any callback that touches an external system (email, Stripe charge, Slack notification, writing to S3) must use after_commit. Callbacks that only mutate the same record's in-memory state are fine in before_save/after_save.
`perform_later` inside a transaction is the same bug, and Rails does not fix it for you by default. With a database-backed queue (Solid Queue, GoodJob, delayed_job) the worker can be running in another process and pick the job up before your transaction commits — the classic ActiveRecord::RecordNotFound on a record you just created. With Redis-backed Sidekiq it is guaranteed to be enqueued even if you roll back.
- In Rails 8.1 the symbol values
:always/:never/:defaultraise; the value is a boolean. - Rails 8.1 removed
config.active_job.enqueue_after_transaction_commit(the 8.1 release notes list it under Active Job removals). Setting it in an initializer configures nothing that reads it. Set it onApplicationJob(and rememberActionMailer::MailDeliveryJobis a separate class that defaults tofalse). - The app-wide config is restored and defaults on in Rails 8.2, which is not released. Do not write code that assumes it.
- Alternative that works on every version: enqueue from
after_commit, or write to an outbox row inside the transaction and enqueue from that. - Keep callback chains shallow. More than 2–3 callbacks on a model means business logic is buried in the model. Move orchestration into a service object that calls the effects explicitly after commit.
4. Transactions — semantics, nesting, and rollback
Nested transactions — the silent swallowing trap:
By default, nested transaction calls join the outer transaction rather than creating a savepoint. raise ActiveRecord::Rollback inside the inner block does nothing — the outer transaction absorbs it without rolling back.
- Irreversible external effects (send email, charge card, publish event) go after commit, never inside the transaction. Guard with an idempotency key (see
mir-backend-ruby— job idempotency). - For contended row updates, use a
SELECT ... FOR UPDATElock:Order.lock.find(id)inside a transaction to prevent concurrent double-processing. - HTTP calls inside a transaction hold a DB connection for the duration of the request to the third party. Under a slow provider this drains the pool and the whole app times out. Move the call out of the transaction.
- With Rails 8 defaults, Solid Queue/Cache/Cable may share the primary database. A long transaction on
primarynow also delays job pickup and cache writes.
5. Migrations on populated tables — the #1 Rails production incident class
AI writes migrations as if the table is empty. Production tables are not empty. Schema changes on large tables take an ACCESS EXCLUSIVE lock; every query behind it queues, and the app times out.
Set a lock timeout first. A DDL statement that waits for a lock blocks everything queued behind it, even if the DDL itself is instant. Fail fast and retry instead:
a) Adding an index without `CONCURRENTLY`
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mir-backend-ruby-rails/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-ruby-rails)