Archive for the ‘Ruby’ Category


Installing Eclipse with Ruby / Rails support

February 28, 2007

eclipse_logo.gifAs stated in my blog, I am having a look at the most well-known Ruby / Rails IDE competitors.
Thus I had a try on Eclipse platform as I couldn’t get RadRails 0.7.2 Standalone version to work with latest RDT plugins that come with refactoring notably.
Version we will install :
Eclipse 3.2.1 with RDT Stable Release (to have a stable environment) or Nightly Build Plugin (in my case to test latest RDT features, and RadRails Plugin 0.7.2
Once you installed Eclipse, you need to install those 2 plugins.
– Help Software Update / Find And Install / Search for new features to Install /
Then Add the new Remote sites :

Eclispe Install RadRails PluginEclispe Install RDT Plugin

Once you parametrized the Ruby SDK in the options, you are ready!


Installing Idea with Ruby / Rails support

February 28, 2007

jetbrains_idea_logo.gifAs stated in my blog, I am having a look at the most well-known Ruby / Rails IDE competitors.
Thus I had a try on Idea which I have been using for years in Java/ JEE.
Version we will install :
Idea 6.0 (Support for Idea Selena (future 7.0) is in the pipes) with Ruby Plugin 0.1.1
You should notice that Idea doesn’t show up when you’re running Beryl on Linux, after switching back to KDE Windows Manager you’ll be able to see the window (You can switch back to Beryl Window Manager after), this a known issue with Java (either 1.5 and 1.6) and Beryl. Eclipse will show up as it is in native swt.
Once Idea installed, you’ll need to install to install Ruby Plugin :
– File / Settings / IDE Settings / Plugins / Right-Click on Ruby plugin.

Idea Install Ruby Plugin

You should also edit bin/idea.vmoptions and increase -Xmx192m

You’ll be prompted to set the Ruby SDK. You might encounter problem with symbolic links on linux when browsing to find your Ruby SDK, or when you generate a Rails project with older version of rails that creates symbolic links in vendor/ which will end in infinite parsing of the project.


Installing NetBeans with Ruby / Rails support

February 28, 2007

NetBeans LogoAs stated in my blog, I am having a look at the most well-known Ruby / Rails IDE competitors.
Thus I had a try on NetBeans after seeing screenshot and features from Tor’s weblog, and after having played in Java with UML Module from NetBeans which I found good, I’ll blog about that later…
So, version we will install :
NetBeans 6 Daily Snapshot (I tried from 20070211 to 20070221). For the moment Ruby support is only available for early adopters in the snapshot releases. It was released lately as 6.0 Milestone 7 (and you’ll wait for M8 for some more features). Modules I installed (with version I have at the moment) :

  • Common Scripting Language API/Support 0.13.0/
  • Embedded Ruby 0.10.0, JRuby Implementation 0.92.3, Rake-Based Project Support 0.10.0, Ruby IDE Support 0.16.0, Ruby On Rails 1.16.0, Ruby on Rails Project Support 0.13.0, Ruby Projects

But latest releases with some more fix/features come with :

  • Common Scripting Language API/Support 0.14.0/
  • Embedded Ruby 0.11.0, JRuby Implementation 0.92.4, Rake-Based Project Support 0.10.0, Ruby IDE Support 0.20.0, Ruby On Rails 1.1600.0, Ruby on Rails Project Support 0.16.0, Ruby Projects

You should notice that NetBeans doesn’t show up when you’re running Beryl on Linux, after switching back to KDE Windows Manager you’ll be able to see the window (You can switch back to Beryl Window Manager after), this a known issue with Java (either 1.5 and 1.6) and Beryl.
Once you installed NetBeans Snpashot (or M07), you’ll need to install the Modules :
– Tools / Update Center / Development Update Center (If you don’t have it available you didn’t download a snapshot release).

NetBeans Install Ruby Plugin

After that for some older version of the module you would need to chmod properly the executable from the plugin directory but this has been fixed here.

When you will try to create a rails project directly after NetBeans install and plugin-install you would end with the error :
rubygems.rb:301:in `report_activate_error': Could not find RubyGem activesupport (= 1.3.1) (Gem::LoadError)
The gems activesupport and activerecord are missing, I found it rather strange as I had them installed on my machine.
In fact NetBeans Ruby Module is using an embedded JRuby, that come with some gems (rails, actionmailer…) used for your future NetBeans Ruby / Rails projects. I wonder why activesupport and activerecord have not been included, but anyway with our project we will need to complete this rubygems repository. It’s important to get that well set as it will be scanned and some features like autocompletion will be based on it.

There is an option in Tools / Options / Miscellaneous / Ruby Application to configure Ruby binaries used by the module.

NetBeans Tools / Options / Miscellaneous / Ruby Application

Still options won’t be saved on Windows, you have to manually edit \.netbeans\dev\config\Preferences\org\netbeans\modules\ruby\ to point to your binaries :
ie, for me :

Congratulations! You are ready, you can relaunch NetBeans and enjoy!
At first launch, the plugin will index Ruby SDK and gems thus taking some minutes.

You’ll find Project Mailing List here.

[EDIT] You can ignore the following workaround as it seems to be corrected with latest versions of the Module since I reported it.[EDIT]

Read the rest of this entry ?


Installing RadRails on Ubuntu Edgy amd64

February 13, 2007

For a future post about Ruby IDE I needed to install RadRails. I did it in the past without problem on windows. Unfortunately the official (and snapshot) versions come with a 32 bits shared library ( So I was landing on an error message quoted later. The only solution I read while investigating on the net was to use RadRails the oldway : install Eclipse and add RadRails and RDT Plugin to it… I didn’t want to download the overbloated eclipse platform while a standalone RadRails version exists which is lighter (still 40MB…) So I convinced myself to get those bloody 64 bits shared libraries to work.
The laziest way is to find a solution without any compilation (compilation of such libraries can be a nightmare when they depend on zillions of projects and I have no fun messing with that anymore).
So let’s go!
Download Eclispe RPC eclipse-RCP-3.2.1-linux-gtk-x86_64.tar.gz from eclipse site.
tar xzvf eclipse-RCP-3.2.1-linux-gtk-x86_64.tar.gz
Get RadRails (0.7.2 or snapshot) from RadRails site
tar xzvf radrails-0.7.2-linux-gtk.tar.gz
Launch RadRails once (you need to do that to init RadRails configuration)
An error message will popup :
An error has occurred. See the log file

By editing this file you’ll read that a 32 bits shared library is doing some mess
java.lang.UnsatisfiedLinkError: /del/radrails/radrails/configuration/org.eclipse.osgi/bundles/59/1/.cp/ /del/radrails/radrails/configuration/org.eclipse.osgi/bundles/59/1/.cp/ wrong ELF class: ELFCLASS32
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(
at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.loadLibrary0(

Backup the existing faulty jar containing the bloody 32 bits library.
mv radrails/plugins/org.eclipse.swt.gtk.linux.x86_3.2.0.v3232m.jar radrails/plugins/org.eclipse.swt.gtk.linux.x86_3.2.0.v3232m.jar.backup
And replace it with the jar you downloaded from eclipse site containing 64bits shared libraries (like
cp eclipse/plugins/org.eclipse.swt.gtk.linux.x86_64_3.2.1.v3235.jar radrails/plugins/org.eclipse.swt.gtk.linux.x86_3.2.0.v3232m.jar
You can finally relaunch RadRails!


How to make a simple image page counter / spyer in 20 minutes with Rails ?

January 27, 2007

At work I was a bit disappointed there is no counter on atlasian confluence wiki. I wanted to know whether my wiki page was being read by people and didn’t want to bug the admin to install the plugin for confluence. And this would be a good occasion to play with my beloved rails.

Prerequisites for your system (here kubuntu) :
I consider that you have rails installed (else sudo apt-get install rails), and mysql (else have a look here). You’ll also need to install mysql driver. First you need to install ruby packaging system : rubygems :
tar xzvf rubygems-0.9.1.tgz
cd rubygems-0.9.1/
sudo ruby setup.rb

Gem needs dev package aswell else you’ll land with a
ruby extconf.rb install mysql
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1

To fix that :
sudo apt-get install ruby1.8-dev
You’ll also need libmysqlclient12 and libmysqlclient-dev :
sudo apt-get install libmysqlclient12
sudo dpkg -i libmysqlclient-dev_4.0.20-2ubuntu1.7_amd64.deb

Finally you can install the driver :
sudo gem install mysql

Create your application skeleton by :
rails counter
Edit counter/config/database.yml and fill your database settings.
Now we will think about the model, what we need to keep ? IP, Browser, when the page was visited and the image visited, can’t be simpler.
ruby counter/script/generate \
model visit

Now you can edit counter/db/migrate/001_create_visits.rb that will be responsible for the database creation and future upgrades.
We will add the column we need :
class CreateVisits < ActiveRecord::Migration
def self.up
create_table :visits do |t|
t.column "ip", :string, :limit => 50, :default => "", :null => false
t.column "created_on", :timestamp, :null => false
t.column "browser_agent", :string, :limit => 100, :default => "", :null => false
t.column "resource", :string, :limit => 30
def self.down
drop_table :visits

Create the schema in mysql (either by commandline or with MySQLQuery Browser for example). Now you can create database table and columns by just running the rake goal :
cd counter
rake db:migrate

If you land on getaddrinfo: Name or service not known it’s likely that you didn’t install the mysql driver (detailed in Prerequisites section).
Ok, we have our db ready, our model, and skeletons.
We will need an image library to create the counter image. I’ll use the popular and easy to use RMagick :
sudo apt-get install libmagick9-dev
sudo apt-get install imagemagick
sudo gem install rmagick

And after some minutes you’ll end with : Successfully installed rmagick-1.15.0 On windows you’ll just need to gem install rmagick-win32

What will be doing our CounterController ? We will render an image showing number of people that requested this image, and add a line to the visits in database. I created an image with framebox public/images/frame_small.jpg to make the counter look a little bit better than a simple number. (Yeah I know I could have created it with RMagick too).
Let’s create our controller CounterController :
script/generate controller Counter
We will add the method show in CounterController (app/controllers/counter_controller.rb) :
def show
@target = @params[:id]
counter_image = \"public/images/frame_small.jpg")
text =
# We count the visitor for the given target resource
counter = Visit.count(:conditions => \
[ "resource = ?", @target])
# puts "Counter for " + @target + " - " + counter.to_s
text.annotate(counter_image, 0, 0, 0, 0, counter.to_s) {
self.gravity = Magick::CenterGravity
self.pointsize = 16
self.font_family = "Verdana"
self.stroke = 'transparent'
self.fill = 'red'
self.font_weight = Magick::BoldWeight
counter_image.format = "GIF"
counter_image = counter_image.to_blob
# The image is created, we can render it as is.
render :text => counter_image, \
:status => 200, :content_type => 'image/gif'

Let’s add a filter to add a line to database, with IP… from the visitor (here we resolve the IP to get the dns which is more talkative in local network as here it contains the name of the user) :
before_filter :complete_stats, :only => :show
def complete_stats
@visit ={:browser_agent => \
request.env['HTTP_USER_AGENT'], \
:ip => Resolv.getname(request.remote_ip.to_s).to_s, \
:resource => @params[:id]})
#puts "Visit created"
#puts "Visit creation failed"

Finally you can test it (-p 80 will specify the port it turns on).
ruby script/server -p 80
You can now browse http://localhost/counter/show/imageA.gif, http://localhost/counter/show/imageB.gif, each time you visit one of them it gets incremented. Now you can insert in any confluence page a link to one of those virtual counter images and keep tracks of your visitors!

Of course this is a really simple version, but enough for my needs. You might check the referrers, count only one visit per ip per day…
You can get rails sources here (easier to read than from this wiki).