Ruby is my favorite programming language, thanks to the expressiveness, the focus on developer happiness and one of the best language communities out there. As a Ruby developer, I can get into a flow at will.

Another big part of Ruby’s shine: the rich ecosystem of gems and tools surrounding it.

Over the years, I have accumulated quite the toolbox when it comes to working with Ruby. Here are some of my personal favorites tools and gems. (I tried not to focus too much on Rails, but obviously Rails occupies a significant space in the Ruby world, so it’s hard to avoid.)

Feedback Loops

A tight feedback loop is a game changer. Shortening your feedback loop will always pay dividends. Here are a couple of tools I use to shorten mine.

I highly recommend watching this talk from one of Test Double’s founders, Justin Searls — especially the section starting at 31:52 where he does the math on the importance of feedback loop. If it doesn’t make you obsessed with its importance, nothing will!

letter_opener

An oldie but a goodie: Letter Opener.

Do you have some flows that are dependent on email? Of course, you do! Think password resets, for example. Your options are:

  • Actually sending the email
  • Looking at the log for the raw email
  • Using a fake SMTP server like Mailhog/Mailcatcher

Or you could just have the email automatically open in the browser!

The letter_opener gem, from Ryan Bates (the creator of RailsCast), does just that.

If you still want an interface/list like what you get with Mailhog/Mailcatcher, you can get one through letter_opener_web.

Letter_opener demonstration
Letter_opener before / after

Live Reload

I feel like I often take live reload for granted nowadays, especially when working with React. But it doesn’t come stock with Rails! So I suspect some of you might still be spamming refresh in your browser. Save your keyboard; automate it!

It’s such an important tool in keeping a tight feedback loop. There are multiple gems to add live reload. My go-to gems for more than a decade have been rack-livereload and guard-livereload, you need both. They are a bit more complicated to install and require running a second process next to the Rails server (guard), but they work on any Rack apps, not just Rails and they make it easy to opt out of live reloading when you need just by killing the guard process.

If your app is a Rails app, you could also look at rails_live_reload. It’s a newer Rails specific gem. I never used it, but it looks a little bit simpler to install.

Livereload demonstration
Livereload

Performance and Debug

rack-mini-profiler

MiniProfiler is a classic; it’s in the default Gemfile of a new Rails app for a reason.

Chances are you’re already using it, but did you know it can do a lot more than just showing the number of SQL queries and the time it took to process the request?

Installing stackprof and memory_profiler allows rack-mini-profiler to help you find your bottlenecks with flame graphs and your memory leaks with a memory profiler.

Something that is not immediately obvious: rack-mini-profiler works even if your app is an API. It collects request data until you make a request to an HTML page. It doesn’t clear its buffer on every request. Just keep an empty “debug” HTML page around or hit your 404 page if your app is a Rails app. (See this StackOverflow issue about rack-mini-profiler and APIs.)

rack-mini-profiler demonstration
rack-mini-profiler

Debugbar

Debugbar is pretty new, so I don’t have much experience with it, but it looks pretty neat, and I will definitely add it to my next project. It is Rails-specific and has significant overlaps with rack-mini-profiler, but I am excited to see it expand (pretty rapidly!) and it has that new car smell.

debugbar screenshot
Debugbar

pp_sql / NiceQL / RailsSQLPrettifier

I’ve used both pp_sql and NiceQL for a long time on various projects now. Both will help you prettify your SQL queries in your logs and in the console.

They are really helpful when trying to understand a complex query. I would not necessarily recommend them in production. In my experience, they affect performance negatively, but they are perfect for development.

NiceQL is not specific to Rails/Active Record. To integrate it with Rails, use RailsSQLPrettifier instead (a wrapper).

NiceQL does syntax highlighting, which is pretty nice! However, it requires a bit of configuration to act on your logs.

pp_sql does the logging out of the box but lacks the syntax highlighting (which might be a feature depending on your use case).

Before:

SQL query in regular Rails log screenshot
SQL query in regular Rails log

pp_sql:

PPSQL screenshot
PPSQL

NiceQL:

NiceQL screenshot
NiceQL

Hirb

Hirb is great when inspecting elements in the console. It’s a mini view framework for IRB/Console. It can handle displaying information in tables and pages. It’s not quite powerful enough to build a full fledge TUI application, but it’s really useful for quickly inspecting data in the console. Say you want to print the attributes of the last 10 signed in users. Hirb would let you display them as a table instead of a bunch of long lines, It makes it a lot easier to visually parse information. It’s not Rails-specific but comes with Active Record support out of the box.

Before:

Before hirb screenshot
Before hirb

After:

After hirb screenshot
After hirb

PGHero

This one is Postgres-specific, but if you’re not running Postgres… well, you should.

PGHero offers a dashboard that will help you manage your Postgres database. It suggests indexes, helps you find N+1 queries, and identifies your slow queries.

Screenshot of PGHero
PGHero

query_count

I think this gem should be available out of the box in Rails. Rails already gives you timing and allocation information; query_count adds the number of queries performed to your logs and lets you assert on the number of queries in your tests. Here’s the last line of a request log as an example:

Completed 200 OK in 75ms (Views: 36.3ms | ActiveRecord: 1.6ms | SQL Queries: 2 (0 cached) | Allocations: 63218)

http://localhost:3000/rails/info/routes

This one is not a gem, but eh, did you know you can hit the /rails/info/routes route in Rails and get a list of your routes? No need to call bin/rails routes. Plus, it’s searchable, and you can toggle between the path and URL helper. Great when you need a quick copy-paste for your views.

Rails routes page screenshot
/rails/info/routes

Data

Scenic / F(x)

Scenic lets you create versioned database views through the Rails migration system and use those views as models as if they were regular tables.

With Scenic, the business logic of very complex pages can be extracted to an SQL query, making the actual Rails code very simple and close to the default CRUD scaffolding (fetch the model, show the model).

F(x) does the same but for database functions and triggers.

If you ever felt the need for an escape hatch from Active Record, the need to run a manual query, take a look at them. They are great! Probably my two favorite gems.

Ahoy / Blazer

Ahoy and Blazer are a pair of tools that allow analytics and data visualization respectively. Before you pull out the big guns when it comes to analytics and data visualization, take a look at Ahoy and Blazer. They might just do what you want for free!

Ahoy (analytics) is powerful because it lets you join across your analytics and your models, without having to send everything to a separate database/data lake. By default it tracks request events groupped by visits and integrates with devise to automatically tag the relevant user on the events. It’s super easy to start tracking custom events from either Ruby or JS.

Blazer (data visualization) is pretty basic, but it’s hard to have an easier setup than that. It lets you make read only queries to your DB and display the results as tables or graph. You can then save or group thoses as dashboards.

Depending on the size of the project, they can bring you pretty far before you outgrow them. After all, they are good enough for Instacart!

Blazer querying capability
Blazer
Blazer graph capability
Blazer dashboards

Other Goodies

Standard

Arguably the most famous gem to come out of Test Double. Rubocop is a massively configurable linter for Ruby. There is so many options that it leaves a lot of room for bikeshedding and decision fatigue.

What if I just want my code to look clean and not to flip flop between double and single quotes every other lines without spending any time in the config?

With Standard you get Rubocop, without any of the configurability! Which might sound like a joke, but (somehow) it’s great! 15M+ download so far, so I must not be the only one finding value in having an easy no nonsense config for a linter.

Middleman

Have you ever wanted to write a small website without pulling in the whole of Rails? Middleman is for you!

Middleman is a static website generator written in Ruby. If you are used to the Rails view layer, you’ll feel right at home.

Active Support

When working in a Rails app, Active Support adds a lot of extensions and utilities to Ruby. Just by habits, I often try to reach for them when working on pure Ruby scripts, only to realize it’s not there. Wouldn’t it be nice if you could get those utilities and extensions without pulling in all of Rails? Well, you can!

I use it often in scrappy one-off scripts. It has come in handy multiple times.

Take a look at the Stand-alone section of the Active Support guide for instructions on how to use it outside of a Rails project

Conclusion

There are tons more Ruby tools and gems I could add to this list. Some of them I reserved because they deserve a whole post to themselves.

Anything you’d add to this list? Join the conversation in the N.E.A.T. community. (Read about the N.E.A.T. community here.)

Joé Dupuis

Person An icon of a human figure Status
Double Agent
Hash An icon of a hash sign Code Name
Agent 0073
Location An icon of a map marker Location
Vancouver, BC