Articles

A collection of my articles on web development, Ruby on Rails, and more.

Run commands using a different ruby version using rbenv

Tags : Ruby rbenv

Published: August 27, 2023

While building a script to test ruby version upgrades in a rbenv-enabled system, I noticed that running bundle install from within a ruby script uses the script’s version of ruby instead of the one defined in the directory.

ActiveStorage fallback for disk storage

Tags : Ruby on Rails ActiveStorage

Published: April 19, 2023

I’m working on an app using DiskService for ActiveRecord storage. To debug a gnarly issue, I had to copy the production database to development, but didn’t want to download the blobs themselves. Here’s how to serve a fallback image when an ActiveStorage file is missing from the storage folder.

How to setup Fontawesome in a Bridgetown website

Tags : BridgetownRB FontAwesome Javascript

Published: March 21, 2023

The Bridgetown documentation is well-written but doesn’t explain everything needed to add FontAwesome, so I documented the steps while converting my website.

Reusable filtering concern for Rails models

Tags : Ruby on Rails Concerns

Published: June 28, 2022

I wanted to implement a generic filtering concern for Rails models, and decided to do things a bit differently from what Justin Weiss and Fabio Pitino did.

Storing settings as JSONB using Rails and PostgreSQL

Tags : Ruby on Rails PostgreSQL JSON

Published: August 17, 2021

You can store native JSON data in Postgres databases, and Rails now allows taking advantage of that format.

Pretty URLs with Rails 6, FriendlyId, and CanCanCan

Tags : Ruby on Rails FriendlyId CanCanCan

Published: July 18, 2020

While building a Rails 6 application, I needed to generate pretty URLs using a model name. I also wanted these URLs to change when the model name was changed, and redirect to the latest URL if someone visited the old URL. As an added constraint, I’m using the CanCanCan authorization gem to handle rights management. Here is the setup I came up with to redirect old URLs while preserving most of the gem’s expected behaviour.