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
an-install 

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"
  end
  Autotest.add_hook :ran_command do |at|
    image_root = "~/.autotest_images"
    results = [at.results].flatten.join("\n")
    results.gsub!(/\\e\[\d+m/,'')
    output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spending?|)/)
    full_sentence, green, failures, garbage, pending = $~.to_a.map(&:to_i)
    if output
      if failures > 0
        notify "FAIL", "#{output}", "#{image_root}/fail.png"
      elsif pending > 0
        notify "Pending", "#{output}", "#{image_root}/pending.png"
      else
        notify "Pass", "#{output}", "#{image_root}/pass.png"
      end
    end
  end
end


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
DOOM_EDITION = false
BUUF = false
PENDING = false
STICKY = false
SUCCESS_SOUND = ''
FAILURE_SOUND = ''

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'
end


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.

Comments

  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"

    to

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

    It worked for me.

    ReplyDelete
  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!! :)

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

    ReplyDelete

Post a Comment

Popular posts from this blog

Building my own home.

I've decided. I want to build my own home. There is something special about building your own things. I built a desk for my tiny room when I first moved to L.A. My room was so small that I had to sit on the bed to use the computer so I build a high desk so I could sit on the bed and work on the computer. My roommate Trentity helped me cut the ply-wood to the right side. I still have that desk. It now sits on the living room covered by a cloth hiding the surplus of costume parts my current roommate Sean uses in his creations. Learning to build and fix things continue. And the feeling of satisfaction from fixing even small things is great. So a few years ago I heard on the NPR program the Story about a couple of educators that moved to a tent in their back-yard so they could rent their house and afford to send their kids to college. They had a special type of tent called a yurt and cooked and showered in an RV they had parked next to it. I thought I could do that. Housing in Lo

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 t

My Fake Resume

Inspired by the over aggrandized bio of Joseph Rakofsky I want to write my own. If you don't know who he is; Joseph Rakofsky is a lawyer who earned a mistrial for a criminal client due to his (alleged) incompetence as reported on the Washington Post . There has been quite a few commentaries on his "Streisand-house" approach of suing all the bloggers and even the Washington Post and American Bar Association for reporting his (alleged) ineptitude. ("Streisand-house" is what happened to Barbara Streisand who wanted to have a picture of her mansion removed from the internet and she sued to have it removed. Unfortunately suing requires the filing of public documents with a picture of her house. The lawsuit had the direct opposite effect it intended. Everybody now could see legally, since it was a public document, a picture of her house.) But all that internet gossip aside I'm most impressed by his resume. Here is a quote from the website: Prior to stud