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

Rajan Bhattarai

Full Stack Software Developer! 💻 🏡 Grad. Student, MCS. 🎓 Class of '23. GitKraken Ambassador 🇳🇵 2021/22. Works with Ruby / Rails. Photography when no coding. Also tweets a lot at TW / @cdrrazan!

195 posts •
Developer tips

Keeping Dependencies Updated — bundle outdated, Dependabot, and When to Hold

There are two failure modes and teams pick one without deciding. Either nobody updates anything until a CVE forces a jump across four major versions in a week, or Dependabot opens eleven PRs

Rajan Bhattarai Rajan Bhattarai 11 min read
Ruby-code

Generate All Combinations Of Array Elements Without Repetition In Ruby

Picking every possible pair of players, every three-item bundle from a catalogue, every subset of feature flags — these are combinations, and Ruby has them built in. No manual nested loops required.

Rajan Bhattarai Rajan Bhattarai 2 min read
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
Developer tips

Common Mistakes Rails Beginners Make (and How to Fix Them)

Every one of these ships to production regularly, and none of them are signs that someone is a bad developer. They’re mistakes Rails makes easy — the framework optimises for getting something working

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails-code

Add A Virtual Attribute To A Rails Model Without A Database Column

A signup form collects a full name that gets split into first and last. A settings form takes a confirmation checkbox that’s never stored. These need to behave like attributes — assignable, validatable,

Rajan Bhattarai Rajan Bhattarai 2 min read
Ruby 3

Safe Navigation, dig, and fetch — Choosing the Right Nil Guard

user&.profile&.address&.city looks defensive and reads as careful code. It’s also a sentence that says “I don’t know which of these can be nil, so I’ve assumed all of them can” — and when

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
Developer tips

Sharing Code Snippets That People Can Actually Use

Someone asks for help and you paste forty lines into Slack. It wraps at column sixty, loses its indentation, and scrolls off the channel in an hour. Or you paste a screenshot of

Rajan Bhattarai Rajan Bhattarai 10 min read
Rails-code

Scope Every Query To The Current User Without Polluting Every Method

Writing current_user.orders.find(params[:id]) everywhere works right up until someone writes Order.find(params[:id]) in a new controller and exposes another user’s data. The fix is to make the scoped path the only path.

Rajan Bhattarai Rajan Bhattarai 2 min read
Developer tips

RuboCop in a Legacy Codebase — Safe Rollout Without the 4,000-File Diff

Someone adds RuboCop to a six-year-old Rails app, runs it, and gets 47,000 offences. The obvious next move — rubocop -A and commit — produces a diff touching every file in the repository,

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails-code

Cache An Expensive Scope In Rails With Automatic Cache Busting On Update

A dashboard query that aggregates across three tables takes 800ms and the underlying data changes a few times an hour. Caching it is obvious; the hard part is invalidating it without a scheduled

Rajan Bhattarai Rajan Bhattarai 2 min read
Ruby 3

StringScanner — Parsing Text Without the Regex Overhead

There’s a stage in every text-parsing problem where the regex stops being the right tool. You’ve got a pattern with four alternations and three lookaheads, it’s slow, it’s unreadable, and it still can’t

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
Developer tips

Setting Up Pre-Commit Hooks for Ruby Projects

A pre-commit hook that runs your full test suite gets bypassed with --no-verify within a week, and then it may as well not exist. A hook that catches a committed binding.pry in 200

Rajan Bhattarai Rajan Bhattarai 11 min read
Rails-code

Eager Load A Rails Association Only When It Exists To Avoid N1

includes(:profile) on a has_one loads a row per record even when most records have no profile. Filtering to the records that actually have the association, or loading it conditionally, keeps the query cheap

Rajan Bhattarai Rajan Bhattarai 2 min read
Page 1 of 13 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! 🚀