Skip to main content

Getting Growl-like notifications on Ubuntu 11.10 in Rails 3.1

I'm doing Michael Hartl's Rails Tutorial book this weekend and I wanted to get the notifications right. Took me a while to get it to work. Since this is a fresh install of Ubuntu 11.10 Oneiric Ocelot I'm running into a few issues. I'm running ruby 1.9.2 using rvm since Ubuntu only included 1.9.1. I'm also using the Gnome 3 Shell as I prefer it to Unity.

1) The first issue was that the execjs gem that is installed by default by Rails 3.1 requires the Spider Monkey Javascript engine to be installed in Ubuntu. (sudo apt-get install libmozjs185 libmozjs185-dev or use Synaptic and search for "spidermonkey" which is what I did). Or you can comment it out of your Gemfile as it doesn't seem to affect anything in the tutorial.

2) The second issue was that I wanted the nice Growl-like notifications for autotest. The instructions on the automate everything website got me there but don't install the gem 'redgreen' it's buggy. Here is the process I followed:

First you need to
sudo apt-get install libnotify-bin
if you don't already have it.

Second install a few gems:
gem install autotest autotest-notification autotest-rails autotest-standalone
Then issue this command

Then modify the .autotest file with the code from automate everything. First I copied the existing autotest file to .autotest.bak and created a new one with this code:

#!/usr/bin/env ruby
require 'autotest/timestamp'
module Autotest::GnomeNotify
  def self.notify title, msg, img
    system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000"
  Autotest.add_hook :ran_command do |at|
    image_root = "~/.autotest_images"
    results = [at.results].flatten.join("\n")
    output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spending?|)/)
    full_sentence, green, failures, garbage, pending = $
    if output
      if failures > 0
        notify "FAIL", "#{output}", "#{image_root}/fail.png"
      elsif pending > 0
        notify "Pending", "#{output}", "#{image_root}/pending.png"
        notify "Pass", "#{output}", "#{image_root}/pass.png"

I actually like the stock images of autotest-notification so I just copied them from their directory here: ~/.rvm/gems/ruby-1.9.2-p290/gems/autotest-notification-2.3.3/images
to the ~./autotest_images/ folder. [Note: I mean ~/.autotest_images/ ]

And it worked. Now I want to figure out if the normal .autotest file would have worked.

# ~.autotest
require 'rubygems'
require 'autotest_notification'
SPEAKING = false
BUUF = false
PENDING = false
STICKY = false

It seems to be able to. Not sure what it does though. If you want to see something fun dig in to the images directory above for DOOM.

Gnome 3 shell Issues: All the notifications seem to remain present on the bottom bar so you can see a sort of notification history; to remove them you have to right click on them.

There is a way to make this notifications transitory which when you're running autotest can be more useful. Go to your ~/.autotest file that you've configured for the Rails tutorial. And add "--hint=int:transient:1" to the notify-send command like below.

3) The third issue was an error regarding the "has_selector" command used on the Static Pages Chapter, this command seems to depend on the gem "webrat" so: gem install webrat 

and change the Gem file section of test to include it:

group :test do
  gem 'rspec'
  gem 'webrat'

And that fixed it.

4) The directory for the css style sheets is no longer /public/stylesheets/ but /app/assets/stylesheets/ so when putting blueprint it should be under /app/assets/stylesheets/blueprint.

5) In the Class section apparently there is a class called Word defined already so I think I broke it when I redefined it, trying to do Hartl's Word example.
I got this error: TypeError: superclass mismatch for class Word

which is pretty nicely explained in this blog. And it means that Word is elsewhere defined (probably further back in the example).

Another cool thing I just noticed is that String#reverse, that only worked for ASCII under Rails 1.8.7 now under 1.9.2p290 works for UTF-8 characters as well so the weird code you see in the screenshot is unnecessary.


  1. To solve the problem of notifications that do not disappear just change line 5 of ~/.autotest from

    system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000"


    system "notify-send --hint=int:transient:1 '#{title}' '#{msg}' -i #{img} -t 3000"

    It worked for me.

  2. Thanks Dan, I updated the blog to reflect this, I actually found it on another blog post about fedora, wish I'd just red your comment it would've been quicker!! :)

  3. I just got the funniest message apparently there is a typo above: it's not ~./autotest_images but ~/.autotest_images, darn decimal point.


Post a Comment

Popular posts from this blog

How to configure Ubuntu's keyboard to work like a Mac's

Typing accents on a PC is a complicated Alt + three numbered code affair. One feels like a sorcerer casting a spell. "I summon thee accented é! I press the weird magical key Alt, and with 0191 get the flipped question mark!" For a bilingual person this meant that writing on the computer was a start-and-stop process. With Mac's it a whole lot easier, just Alt + e and the letter you wanted for accents and alt + ? for the question mark. No need to leave the keyboard for the number pad and no need to remember arcane number combinations or have a paper cheat sheet next to the keyboard, as I've seen in virtually every secretaries computer in Puerto Rico.

Linux has a interesting approach to foreign language characters: using a compose key. You hit this key which I typically map to Caps Lock and ' and the letter you want and voilá you get the accent. Kinda makes sense: single quotation mark is an accent, double gets you the ümalaut, works pretty well. Except for the ñ, wh…

Contrasting Styles of Writing: English vs. Spanish

There is interestingly enough a big difference between what's considered good writing in Spanish and English. V.S. Naipul winner of the 2001 Nobel prize for literature publish an article on writing. In it he emphasizes the use of short clear sentences and encourages the lack of adjectives and adverbs. Essentially he pushes the writer to abandon florid language and master spartan communication. This is a desired feature of English prose, where short clipped sentences are the norm and seamlessly flow into a paragraph. In English prose the paragraph is the unit the writer cares about the most.

This is not the case in Spanish where whole short stories (I'm thinking this was Gabriel Garcia Marquez but maybe it was Cortázar) are written in one sentence. Something so difficult to do in English that the expert translator could best manage to encapsulate the tale in two sentences. The florid language is what is considered good writing in Spanish but unfortunately this has lead to what …

Fixing Autocomplete in Github's Atom Text Editor for Ruby

I really like Github's Atom Text Editor. I really like that it's multi-platform allowing me to master one set of skills that is transferable to all platforms and all machines. 

On thing that just burns me of the default set-up in Atom is the Autocomplete feature that seems to change my words as a type them. Because Ruby uses the end of line as a terminus for a statement you usually finish a word with pressing the return button and you get really annoying changes to your finished typed word a la MS Word. I find myself yelling "No that's not what I wrote!" at the screen in busy coffee shops.

I disabled autocomplete for a while but it is a very useful function. Then I found out they changed the package that gave the autocomplete to a new one called "Autocomplete Plus" that gives you more options. All that I needed to change to make autocomplete sane again:

1. Open Atom's Preferences
2. Search the bundled packages for "Autocomplete Plus"

3. Go to t…