anantbhandarkar/make-it-right/mir-backend-ruby-rails

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

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-rails

SKILL.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)

ChangeVersionWhat it means for your code
params.expect8.0The 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 apps8.0Jobs, 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 authentication8.0Sessions table + has_secure_password + rate_limit. Authentication only — no registration, confirmation, MFA, lockout, or authorization — see Security
rate_limit to:, within: on Action Controller8.0Built-in throttling; the auth generator ships one on SessionsController#create
enqueue_after_transaction_commit symbol values and the app-wide config both removed8.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 removed8.1Switch to the adapter shipped by the sidekiq gem (requires sidekiq ≥ 7.3.3)
include ActiveJob::Continuable8.1Long 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.1A second place application data leaves the process. config.filter_parameters does not filter it
Associations can be marked deprecated: true (:warn / :raise / :notify)8.1Use :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 deprecated8.1Add explicit .order(...) before .first/.last; these become errors later
Leading-bracket param parsing, ; query separators, multi-path routes removed8.1Old 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.

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:

MethodSQL shapeUse when
preloadTwo separate queries, alwaysAssociation is large; you don't need to WHERE on it
eager_loadSingle LEFT OUTER JOINYou need to filter/sort by the association (where("users.role = ?", "admin"))
includesPicks preload or eager_load automatically based on whether a references or where clause touches the associationDefault — let Rails decide unless behavior is surprising
  • Bullet gem (gem "bullet") detects N+1 and unused eager loads in development/test — add it to Gemfile and enable in config/environments/development.rb.
  • `strict_loading`: Order.strict_loading.all raises ActiveRecord::StrictLoadingViolationError on any lazy association access — zero-overhead enforcement in CI.
ruby
# Model-level enforcement
class Order < ApplicationRecord
self.strict_loading_by_default = true
end

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!).

ruby
# WRONG — permits any param the attacker submits (is_admin, role, tenant_id)
params.require(:user).permit!
# LEGACY — works, but `?user=hello` makes `permit` run on a String -> NoMethodError -> 500
params.require(:user).permit(:name, :email, :password)
# RIGHT (Rails 8) — one step, structure-checked
params.expect(user: [:name, :email, :password])

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 create vs update when 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.

ruby
# WRONG — email fires inside the transaction; rolls back -> sent but no record
after_create :send_welcome_email
# RIGHT — fires only after the transaction commits successfully
after_commit :send_welcome_email, on: :create

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.

ruby
class SendReceiptJob < ApplicationJob
self.enqueue_after_transaction_commit = true # per job class — Rails 8.1
end
  • In Rails 8.1 the symbol values :always / :never / :default raise; 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 on ApplicationJob (and remember ActionMailer::MailDeliveryJob is a separate class that defaults to false).
  • 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
ruby
# Explicit transaction block — all-or-nothing
ActiveRecord::Base.transaction do
order.update!(status: "paid")
payment.update!(confirmed: true)
# raise ActiveRecord::Rollback here to abort without re-raising to the caller
end

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.

ruby
# WRONG — inner rollback is silently swallowed into outer tx
ActiveRecord::Base.transaction do
outer_work
ActiveRecord::Base.transaction do
raise ActiveRecord::Rollback # <-- ignored; outer tx continues
end
end
# RIGHT — savepoint gives the inner block true rollback semantics
ActiveRecord::Base.transaction do
outer_work
ActiveRecord::Base.transaction(requires_new: true) do
raise ActiveRecord::Rollback # rolls back to savepoint only
end
end
  • 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 UPDATE lock: 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 primary now 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:

ruby
class AddRegionToOrders < ActiveRecord::Migration[8.1]
def change
# bounded wait; better a failed migration than a stalled app
execute "SET LOCAL lock_timeout = '5s'"
add_column :orders, :region, :string
end
end

a) Adding an index without `CONCURRENTLY`

ruby
# WRONG — acquires a lock that blocks writes for the duration of the build
class AddIndexToOrders < ActiveRecord::Migration[8.1]
def change
add_index :orders, :user_id
end
end
# RIGHT — disable_ddl_transaction! is a CLASS-level statement, not a line inside change
class AddIndexToOrders < ActiveRecord::Migration[8.1]
disable_ddl_transaction!
def change
add_index :orders, :user_id, algorithm: :concurrently
end
end

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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-ruby-rails/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-ruby-rails)

Something wrong with this skill or its page? Tell us.