Sunday, 6 December 2009

A Click Heat Map plugin for ruby on rails applications

Hi Rubysts,

I've just finished my first contribution to the Ruby on Rails community this evening.
This contribution is actually the repackaging of the click heat map generator included within cannoli into an easy-to-install and deploy ruby on rails plugin.

If you take a look at cannoli you observe that it is based on ruwa web analytic ruby on rails app. I didn't need all of these together.
So... Did I manage to do something better? I believe that it is only rarely the case for something to be in every aspects better than something different. In this particular case I would say that I have made a piece of ruby on rails building block which is less than cannoli but it can be extremely easily incorporated in your Rails ( >2.3.2 ) application.

It has it's own requirements:
  • you need Rmagick installed
  • you must have Rails 2.3.2

Maybe you want to improve your sites web usability.
In order to install the plugin:
  • ./script/plugin install git://
From the click_heat_map plugin directory (not from rails root)
  • rake db:migrate:click_heat_map
Then you need to put and adapt this code into your templates:
< src="'/javascripts/overlay.js'" type="'text/javascript'">
< src="'/javascripts/clickmap.js'" type="'text/javascript'">

put this html code into your templates you want to measure:
< id="prova" style="margin:auto;width:800px;height:1px;">

And finally, you reached the point where you want to deploy your rails app using capistrano.
Maybe you ask yourself how capistrano knows how to migrate your plugin to the remote server.
In my case I put the installed plugin under version control and Capistrano just copied to the remote server.
I also created a file named
require 'vendor/plugins/click_heat_map/lib/db/migrate/20091130000000_create_heat_map_clicks.rb'
This way capistrano creates the tables needed by the plugin on the remote server by running "cap deploy:migrations".

Finally the result makes me happy :)

Wednesday, 4 November 2009

A quick fix for swfir and prototype incompatibility


Some of you might know about a small and smart library called swfir. This library intends to extend some of the limitations of classic html images. It can rotate the images and it can draw some fancy borders and fancy shadows around the borders and so on. I like the library despite the fact that it's not perfect. It's not compatible with prototype. :(

Here is a small patch that I posted to the authors and hopefully a new release will come out which will support prototype :)

Untill then you can use the patch from here:

@@ -569,7 +569,11 @@
Flash Vars
var varString = "";
- for(va
r key in this.params){ varString += ("&"+key+'='+ this.params[key]); }
+ for(var key in this.params){
+ if("function" != typeof(this.params[key])){
+ varString += ("&"+key+'='+ this.params[key]);
+ }
+ }
Rendering before:

Rendering after: