It comes as a surprise to absolutely no one that I’m a huge fan of the Rails Console and I advocate its usefulness for anyone learning about Ruby on Rails. In the early days of Rails, the Console was frequently overlooked in favor of some of the sexier parts of Rails but once you find yourself spending any significant amount of time inside of a Rails application, the Console quickly becomes one of your favorite tools.
That said, the Rails Console is far from perfect and before long you’ll inevitably find yourself wishing it was able to do this or that and you begin exploring possible enhancements & alternatives. One of the things that I initially wanted the Console to do a better job of was in helping me getting a better grasp in what was happening in my Rails app. I really wanted be visualize the output of some of what it was telling me.
Before too long I had added in Wirble which provided several nice enhancements to irb (which you can learn several good tips and tricks here) and life was good but being human I was left looking for other possibilities.
This path ultimately lead me to Hirb which is essentially a small view framework designed specifically for console based applications which not so ironically deals beautifully with irb and the Rails console. The official docs on its GitHub page explain xxx as:
Hirb currently provides a mini view framework for console applications, designed to improve irb’s default output. Hirb improves console output by providing a smart pager and auto-formatting output. The smart pager detects when an output exceeds a screenful and thus only pages output as needed. Auto-formatting adds a view to an output’s class. This is helpful in separating views from content (MVC anyone?). The framework encourages reusing views by letting you package them in classes and associate them with any number of output classes. Hirb comes with tree views (see Hirb::Helpers::Tree) and table views (see Hirb::Helpers::Table). By default Hirb displays Rails’ model classes as tables. Hirb also sports a nice selection menu, Hirb::Menu.
Installation is standard enough via Ruby Gems with:
sudo gem install cldwalker-hirb –source http://gems.gith
and you can quickly get into the swing of things via the Rails console via a simple call as follows:
bash> script/console
Loading local environment (Rails 2.2.2)
irb>> require ‘hirb’
=> true
irb>> Hirb.enable
=> nil
What awaits you is a much more visual experience in your Rails console. Not wanting to spoil the ending for you, I encourage you to checkout hirb’s GitHub page. These are still early days for me and hirb but so far, I like what I see and it only makes me want to dig deeper into the Rails Console to see what other tricks are hiding in there.
Comments on this entry are closed.