Upgrading the script/console in Windows VISTA environment

December 10, 2009 at 1:03 am 4 comments

If you haven’t been actively using script/console – you should start it now. It allows you to test things out in the environment of your project with a direct feedback. So, if you want to check those quirky database queries or how a new plugin works, run the script/console and start coding.

However, as seemingly everything in Ruby Rails, the console is a bit buggy in Windows. This calls for a console upgrade. At the same time we will include some further improvements as well to make your console the best firend.

1. Buggy cursor. Try it for yourself – type a very long line of code and try to move cursor – chances are it will get screwed up at some point in time – the cursor will jump, etc. The problems is with a module called readline. It’s a part of Ruby and was not updated from 2005, and nobody bothered to fix it for Windows. So, the only option is simply to disable it in your irb.bat file by adding the –noreadline switch like that:

IF NOT "%~f0" == "~f0" GOTO :WinNT
@"C:\Ruby\bin\ruby.exe" "C:\Ruby\bin\irb" --noreadline %1 %2 %3 %4 %5 %6 %7 %8 %9
"%~d0%~p0ruby.exe" "%~d0%~p0%~n0" --noreadline %*

Now, you won’t be able to use auto complete features of your console (tab), but the cursor works and the auto complete was not that useful for me.

While there, create a shortcut file called rc.bat in the ruby/bin directory, and insert there:

ruby script/console

2. Install HIRB and Wirble. HIRB is a nifty gem returns ActiveRecord objects in an SQL like table, which makes it much more readable:

irb>> Tag.last
  | id  | created_at              | description | name          | namespace | predicate | value |
  | 907 | 2009-03-06 21:10:41 UTC |             | gem:tags=yaml | gem       | tags      | yaml  |
  1 row in set

To install hirb run: gem install hirb

Wirble does some colorizing stuff, although I have to say the default color scheme looks awful. To install wirble run: gem install wirble

You will also need to install win32console to get ANSI color support: gem install win32console

3. Now, automatically add HIRB (tabular query results), Wirble (color) and showing resulting SQL queries to the console.

In C:\Users\[your user name] create a file called “.irbrc” and paste these instructions there:

# allaboutruby.wordpress.com script/console configuration
# v 1.0, 2009 Nov

  require 'rubygems'

# load hirb
  require 'hirb'
  extend Hirb::Console

# load Win32Console
  require 'Win32/Console/ANSI'

# start wirble (with color)
  require 'wirble'

# show SQL statements on in console mode
  if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
    require 'logger'
    RAILS_DEFAULT_LOGGER = Logger.new($stdout)

So, now you have a modified console that works much better than the out of the box solution.


Entry filed under: Uncategorized.

vote_fu to work in Heroku (Postgres) Commenting out chunks of view

4 Comments Add your own

  • 1. Daniel Berger  |  December 11, 2009 at 3:14 am

    I think it’s an issue with the C bindings. When I run rb-readline instead, it works fine.

    • 2. allaboutruby  |  December 12, 2009 at 11:12 am

      I didn’t try rb-readline before, thanks for the tip. I’m not using the autocomplete though, and the Windows command history works well, so not too many reasons to switch, I guess…

  • 3. Drew  |  April 26, 2010 at 7:07 pm

    Thank you very much for this post. This bug has pissed me off for a long time.

  • 4. Nik  |  May 10, 2010 at 7:48 am


    Thank You thank you thank you for writing this article, I thought I was the only one experiencing this.
    @allaboutruby: how can I use rb-readline? Do I have to download something and replace some files in the ruby bin directory with the downloaded?



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

Recent posts

Starting to learn Rails?


Get Kindle - the best e-book reader, that I personally use, and the only one that you can read on the beach - very useful: Kindle Wireless Reading Device (6" Display, Global Wireless, Latest Generation)

%d bloggers like this: