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

What Medieval Economics can teach us about tariffs.

As a teen, I used to play Dungeons and Dragons (D&D) with my friends. This started an interest in the medieval period that led to me taking a medieval history class in college just to understand the period more. Over the years I've also read great books like " Dungeon, Fire and Sword " about the crusades (I recommend the book) and yet with all that knowledge it wasn't until recently that it occurred to me I had a completely wrong understanding of economics in the Medieval Period. "Viking helmets, sword and footwear" by eltpics is licensed under CC BY-NC 2.0 In my D&D games, players who are adventures battling monsters and creatures would need equipment and on the trips to town, they'd get resupplied with their adventuring necessities. I'd run these moments referencing my imagination of what it must have been and fantasy books I'd read. There be an inn with a raucous bar, a gruffly black-smith, if a city also a weapon and armor sm...

Great iPhone Apps

As a companion to my blog on Windows utilities, here are two paid apps on the iPhone that I consider so fantastic that are must buys in my opinion. -Easy Calendar ( $1.99 ) The iPhone Calendar is one of its weakest features in my opinion. I miss the clear Black Berry calendar on my pearl whenever I had to use it. This app makes the calendar not only easy to use but way more useful, I see my week laid out for me with an easy ability to push things to other days (rather than having to re-enter the appointment). This app has completely re-made the way I organize things. I'm way more organized and rarely miss appointment now. This app is a steal at it's prize. No other app adds such simple functionality to the iPhone like this one does. It's like my secret organizer helper. -Sleep Cycle ( $.99 ) I tried out this app because it was recommended on Tim Ferriss's books . I had seen this app before when it came out and thought it was intriguing, but it was way expensive. N...

Best Tech Books

Best Tech Books for Programming Language Learning I'm a bit of a polyglot no only in human languages (English, Spanish, Japanese) but also with programming languages. I found that the best way to get a deep understanding of the programming field, I needed to be broad. I got introduced to Bruce Tate's 7 languages in 7 weeks series right when I was starting to learn Ruby and found the cross-language trends to be very useful in knowing what to learn for the future.  So here is a list of Programming Books that I found good for learning a language. These are the must have books in my opinion to "get" or "grok" the language. Most of these books I have not finished but they're so good I can recommend them for other language learners and polyglots. All these books should accelerate your learning dramatically.  Poignant Guide to Ruby Ruby: POODR and _why's Poignant Guide to Ruby .  Okay, so _why's Poignant Guide to Ruby is the reason I fell in love with ...