← mattbrictson.com

Matt’s Blog

Hi! I’ve been building web apps and managing Ruby open source projects throughout most of my career – leading engineering teams at Bay Area tech companies, as well as managing my own freelancing clients. This blog is my way to record what I’ve learned so that I don’t forget. 😄 I hope you find something interesting here as well! —Matt

RSS
Last updated 4 months ago
Subscribe in Feedbin

Archive

October 2023

Simplify your Capybara selectors
How to use a Ruby-friendly syntax alternative to esoteric CSS and xpath expressions. Plus, a trick for making Capybara automatically aware of data-testid attributes.

7 Lesser-Known Features and Changes in Rails 7.1
Rails 7.1 lacks big show-stopping additions, but there are still many improvements to the developer experience that are worth checking out.

Bundler 2.4.20 understands .ruby-version files
You can now DRY up your Ruby version declarations with Bundler’s new Gemfile syntax.

August 2023

Fixing Thor’s CLI Quirks
I’ve been wanting to build a CLI in Ruby, and Thor is the obvious library to use. But Thor has some weird behaviors that were driving me crazy. Here’s what I found, and how I extended Thor to fix it.

Speed up your default Rake task with the multitask -m option
I recently discovered that Rake has the ability to run tasks in parallel. For Rails projects with many test and linting tasks, this can be a huge time-saver.

The Hidden Complexities of Running Shell Commands in Ruby
Did you know that system supports the equivalent of > dev/null output redirection? And that backticks raise an exception when a command isn’t found, but system does not? Let’s go on a deep dive into the Ruby standard library!

Safe redirects in Rails 7
Enforcing canonical URLs by redirecting to params is not safe and may raise an exception. Use strong params with allow_other_host: false for security.

July 2023

Automate Rails deployments with GitHub Actions
A continuous deployment recipe than can be applied to Tomo, Kamal, Capistrano, and other SSH-based CLI tools.

How to organize CSS in a Rails project
Don’t overthink it! Start with a simple base set of styles and refactor by extracting files and shared components as you go.

Don’t reinvent the wheel with Rails exception handling
With the built-in rescue_responses setting, you can map exceptions to error pages in a simple, declarative way. It automatically renders JSON, too!

Making the case for CSS normalize and reset stylesheets in 2023
If you’re embarking on writing CSS without a framework, adopting a normalize and reset stylesheet should be your first step. Here’s what I recommend.

Fixing slow, flaky system tests in Vite-Rails
Turn off autoBuild.

June 2023

Improve your GitHub workflow with better repository defaults
Starting a new project? Set your team up for success with these opinionated GitHub repository settings.

Tips for writing Rails tasks with Thor instead of Rake
Thor is a great way to write simple CLIs like one-off Rails scripts, but it does have its own gotchas. Here’s how to use Thor in practice.

Applying a Rate Limit in Sidekiq
I discovered an easy way to implement job throttling using the ruby-limiter gem and the new “capsules” feature of Sidekiq 7.

The 3 Vite plugins I use on every new Rails project
Autoprefixer, rollup-plugin-gzip, and vite-plugin-full-reload, plus some honorable mentions

May 2023

Inline SVGs with Rails and Vite
Here’s one way to add Vite support to the popular inline_svg gem, plus a way to implement your own helper and skip the gem dependency altogether.

The Gateway Pattern
Use gateway classes to organize external API integrations and establish a clearer separation of concerns.

Advanced techniques for calling HTTP APIs in Ruby
How to use Faraday and other gems to implement circuit breakers, gracefully handle API rate limits, pool connections for better performance, and more.

Automatically open the browser when the Rails server starts
Create React App has done this since 2016. Why not Rails?

Configuring Rails and Vite to use HTTPS in local development
The localhost gem does most of the heavy-lifting.

April 2023

October 2015

Accelerated Rails Downloads with NGINX
Rails has an option to enable X-Accel-Redirect, but that is not the whole story. To get it working, NGINX has to be configured as well, and it is a bit tricky. Here is what I figured out.

August 2015

2 Under-Appreciated Rails Commands
Easily undo scaffolding mistakes with rails destroy and execute arbitrary code from the command-line with rails runner.

A Recipe for Rails Continuous Integration
At its most basic, continuous integration (CI) is just a process that checks out the latest code commit and runs a script. What that script does is up to you. In this article I’ll share the script I use for my own Rails projects, and the reasoning behind it.

July 2015

Generating Gzipped Assets for Nginx in Rails 4.2
Nginx has the ability to serve static .gz files instead of compressing assets on the fly, which is great for performance. Unfortunately, Rails recently dropped its support of this feature. Here’s how to restore it.

The Best of RailsConf 2015
It’s been a few months since this year’s RailsConf, but the videos are now all posted online and there is plenty of great content to digest. Here’s a short list of my favorite talks and what I took away from each one.

How to Test Ruby Projects on Windows
AppVeyor is a continuous integration service like Travis CI, except that AppVeyor runs on Windows servers. I’ve found that it can be an easy way to test that a Ruby project works in a Windows environment. Here’s how to set it up.

Building a Ruby Gem in 2015
I recently released “chandler”, a small Ruby gem for managing GitHub release notes. It started as an idea to scratch an itch, turned into a weekend project, and then into a full-blown open source Ruby gem. Here’s what I learned along the way.

May 2015

A Better Way to Purchase and Install SSL Certificates
Did you know it’s possible to purchase new SSL certificates from the command line, and automatically renew those certificates with a simple cronjob? In this tutorial I’ll walk you through using the sslmate command-line tool, plus show you how to configure Nginx to earn an “A+” HTTPS security rating.

Speed up Rails with Nginx’s Reverse Proxy Cache
Nginx is a great web server for Rails apps, but did you know it also has powerful caching abilities? Here’s how to turn on reverse proxy caching in Nginx for an impressive performance boost.

April 2015

ActiveRecord Strict Validations, Minitest, and Shoulda
Are you using thoughtbot’s Shoulda gems with Minitest? How about strict validations in ActiveRecord? Here’s why I think these are great things to add to your Rails backpack of tools, and how to set them up.

Setting up Sublime Text 3 for Rails Development
I’ve been a satisfied Sublime user for the past three years, using it primarily for Rails development. Here are the packages, preferences, and tips I recommend for getting the most out of this excellent editor.

Use Minitest for Your Next Rails Project
Minitest is a fast, easy to read alternative to RSpec for writing Rails tests, but it can be confusing at first. Here’s how I set up Minitest with Rails, and the gotchas I encountered along the way.

March 2015

Managing Complex Tasks in Trello
Trello tasks are great for simple to-do lists. But what about managing more complex tasks or interdependent tasks? Part 3 of my series on managing software projects in Trello.

Using Trello Labels to Track Software Estimates
How I use labels to track estimates, measure capacity, and keep scope creep under control. Part 2 of my series on managing software projects in Trello.

A Closer Look at Airbrussh
How I applied a UI and UX mindset to improve the format of Capistrano’s logging output.

Estimating Software Projects with the ••• System
Or: how I trick my brain into making more accurate estimates.

February 2015

Using Trello Boards to Organize Software Projects
An introduction to how I use Trello boards and lists to organize my freelance projects. Part 1 of a series.

The Registry Pattern
Using a Registry to look up collaborators in Rails, like external APIs.

Build and Deploy a Rails VPS, Part 1
Start by provisioning an Ubuntu 14.04 VPS, then install Ruby with rbenv.

Build and Deploy a Rails VPS, Part 2
“Capify” a new Rails app and deploy it to your VPS using Capistrano and Puma.

Dynamic Rails Error Pages
Build custom 404 and 500 error pages utilizing ERB and your existing layouts and stylesheets.

March 2014

Upgrading to Rails 4 with Capistrano
What to watch out for when doing your first deploy after upgrading from Rails 3.

February 2014

Easier Nested Layouts in Rails
Clean up your views with this simple idiom for writing and declaring nested layouts. Now updated for Rails 7.

September 2013

Running capybara-webkit Specs with Jenkins CI
How to get WebKit-driven integration tests working in a headless Linux environment.

Upgrading PostgreSQL 9.2 to 9.3 with Homebrew
What to do when PostgreSQL fails to start after a brew upgrade.

Setting Up HTTPS with Nginx
My workflow for purchasing an SSL certificate and installing it in Nginx.

Rails OS X Setup Guide
Installing an rbenv-based Rails stack on El Capitan, Yosemite, or Mavericks

January 2013

Applying SMACSS to Rails Projects
How to organize your stylesheets in the asset pipeline.

Lightning-Fast Sass Reloading in Rails
How to configure a Rails project with LiveReload and speed up your front-end workflow.

May 2012

TLS Error with Ruby Client and Tomcat Server
Temporarily work around the problem with a simple client-side hack.

Faster Capybara Specs
How to use the database_cleaner gem without slowing everything down.

April 2012

February 2012

Untangling the Rails Asset Pipeline, Part 3
Making sense of the configuration options.

Untangling the Rails Asset Pipeline, Part 2
Making it work in production.

Untangling the Rails Asset Pipeline, Part 1
Dealing with caches, and: do you really need Compass?

January 2012

Invoke Rails and Rake Faster!
A handy shell function for running rails and rake commands with fewer mistakes.