Using Hirb to Organize Queries in the Rails Console

Feature thumb snip20170622 40

Running queries in the Rails Console can be a bit messy, to say the least. For example, when I run a query to find the last DailySmarty posts, the query result set looks something like this:

This can make it very difficult to comb through the data, which is where the Hirb gem comes in. If I add gem 'hirb' to the Gemfile and run bundle, I can start the rails console back up and type:

Hirb.enable

 

And now if I run a query, Hirb automatically formats the resulting output, as shown below:

This replicates the type of view that you would get if you were directy connected to the SQL database and it much easier to quickly go through.

When working with database tables and complex queries, this can make life much easier to visualize the data. The link below adds some additional examples and other IRB/Rails console tooling customization.