FirstDEV blog
  • Home
  • Ruby
  • Ruby On Rails
  • Tips
  • Solutions
  • About
Subscribe

Rails

We cover Rails 6.x / 7.x

Rails

Multi-Tenancy in Rails — Row-Level vs Schema-Level, and the Cost of Each

Every B2B application eventually needs tenant isolation, and the decision gets made early — usually by whoever writes the first migration, usually without a discussion. Three months later you find out whether it

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

Rails Form Helpers and ViewComponents — A Practical Guide

Your form markup is forty lines per field: a label, an input, a conditional error span, three utility classes, an aria attribute someone added once. Multiply by eleven fields and six forms and

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

Understanding Zeitwerk — Rails' Autoloading Engine, Explained

uninitialized constant Billing::PDFGenerator on a file that unmistakably exists at app/services/billing/pdf_generator.rb. Or a class that loads fine in development and vanishes in production. Or a change to a model that doesn’t take effect

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails

Request Specs vs Controller Specs — What to Test at Each Layer

Controller specs let you call an action directly and assert on assigned instance variables. They’re fast, they’re focused, and the Rails team has been steering people away from them for years. The reason

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails

Bulletproofing Rails Migrations — Zero-Downtime Strategies for Large Tables

rails db:migrate on a forty-row development database takes eleven milliseconds. The same migration against a forty-million-row production table takes an ACCESS EXCLUSIVE lock, queues every query behind it, exhausts the connection pool, and

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

with_options — DRY Validations and Routes Without the Abstraction Tax

Six validations in a row, each ending with the same if: :submitted?. Four routes sharing the same constraint. Three associations with identical dependent: :destroy, inverse_of: options. The repetition is noise, but the usual

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails

Rails System Tests With Capybara — Setup, Speed, and Staying Sane

System tests are the ones that catch the bugs nobody else does — the form that submits fine but whose success message never renders, the Turbo Frame that silently swallows a redirect. They’re

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

Rack Middleware From Scratch — What Lives Between the Internet and Your Rails App

Before a request reaches your controller it passes through roughly twenty pieces of code you didn’t write. Session handling, cookie parsing, parameter decoding, flash messages, exception rendering — all of it is Rack

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

Database Indexing for Rails Devs — Composite, Partial, and What EXPLAIN Is Telling You

Rails makes it easy to write a query and hard to see what it costs. add_index on every foreign key is the standard advice and it’s a decent floor, but it doesn’t help

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

Turbo Native — Wrapping Your Rails App in an iOS and Android Shell

A native app is three codebases: the web app, the iOS app, and the Android app, each reimplementing the same screens and drifting apart. Turbo Native takes a different position — your Rails

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

counter_cache and touch — Derived Data in Rails Without the Extra Query

An index page listing fifty posts, each showing a comment count, issues fifty-one queries. The fix is well known — counter_cache — and it’s usually applied incorrectly, either by forgetting the backfill, by

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

ActiveRecord::Store — Structured Data in One Column Without a Migration Per Field

Some data doesn’t deserve a column. User interface preferences, per-account feature toggles, the last three filters someone applied to a report — attributes that are read constantly, queried almost never, and change shape

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails

Background Job Architecture — Retries, Dead Queues, and Idempotency in ActiveJob

ChargeCustomerJob.perform_later(order) looks like a function call and behaves like a distributed system. It runs on another machine, at an unknown time, possibly more than once, possibly never. Most job bugs come from writing

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails

Strict Loading in Rails — Eliminating N+1 at the Framework Level

Every Rails team has the same conversation eventually. Someone adds bullet to the Gemfile, fixes the twelve N+1 queries it finds, and six weeks later there are eight new ones. Detection tools tell

Rajan Bhattarai Rajan Bhattarai 9 min read
Rails

Solid Cache — Replacing Redis With Your Database, and When Not To

Every Rails app reaches the point where it needs a cache store, and the reflex answer has been Redis for a decade. Solid Cache challenges that by putting the cache in the database

Rajan Bhattarai Rajan Bhattarai 10 min read
Page 1 of 3 Older Posts »
FirstDEV blog © 2026
Proudly published with Jekyll & using Jasper2
Latest Posts Twitter
FirstDEV blog

Check viewARU - Brand Newsletter!

Newsletter to DEVs by DEVs - boost your Personal Brand & career! 🚀