Railsy WURFL
There are a couple of scripts and tools for Ruby that work with the WURFL data, but there didn’t seem to be much for ruby based applications to do what most web apps really want to do: lookup device capabilities based on the user agent of a request. I was doing some ruby WURFL stuff at work, and I’ve been playing around with a mysql backed WURFL lookup for PHP called tera-wurfl. And then I got to thinking “Hey, for most of what you would want to do with WURFL you would just need to load the device entries and capabilities into two simple tables and it should take like a dozen lines of ActiveObject hackery and some string comparisons to make a WURFL lookup for Rails apps”.
Looks like I was just about right, though I haven’t checked the line counts to make sure the estimate was on target. It’s still pretty rough, and inefficient enough that it might actually deserve the term “belligerent programming”, but you gotta start somewhere: ruby-wurfl-1.0.tgz. There’s a README file in there that describes how to get it working, which could probably be hooked into all kinda of slick rails coolness. But it’s not.

May 8th, 2007 at 12:47 pm
Very cool! I’m new to the wurfl and seeing some rough edged rails specific stuff is extremely helpful. thank you for this.
May 15th, 2007 at 9:01 pm
Excellent, I’ve been meaning to do this for about 2 years now. I think you are right, there are probably very elegant ways to integrate this, I think it might have to do with the responds_to functionality added as part of rails 1.2 for REST functionality.
It’s an excellent start, I hope to have time to play with it!
June 9th, 2007 at 12:12 pm
Mike, I was just starting to teach myself Rails and this was also my first idea for a project. Thanks for the jumpstart! I am thinking about extending the functionality to include a UI for “correcting” the WURFL and generating a WURFL patch file from the database. It would also support the ability to add custom properties to the patch.
June 9th, 2007 at 12:56 pm
Hey Rodney, Great ideas! Let me know if you work through some of them, I would love to give them a try and start to really spin up an official WURFL Rails plugin. - Mike
July 18th, 2007 at 3:33 am
Great bit of work, cheers Mike. Just modified line 73 to;
if user_agent.index( ‘Gecko’ ) and !user_agent.index( ‘Nokia’)
Because a N95 uses Gecko (and I think preceding phones) and this was preventing it from returning a record.
December 14th, 2007 at 11:25 am
Any more updates on this? I’d suggest putting it on Google Code to release it for evolution.
This is an important and necessary project; good work.
January 25th, 2008 at 6:05 pm
Mike - Thank you. Very easy to implement, lovin’ it.
May 4th, 2008 at 11:56 pm
Very simple and easy to use. Made my day. Only required a tiny change:
— orig/ruby-wurfl-1.0/wurfl_db_inserts.rb 2007-01-06 22:15:46.000000000 -0500
+++ ruby-wurfl-1.0/wurfl_db_inserts.rb 2008-05-05 00:36:54.000000000 -0400
@@ -21,7 +21,7 @@
#
require ‘rubygems’
-require_gem ‘activerecord’
+require ‘activerecord’
require ‘rails/app/models/wurfl_device’
require ‘rails/app/models/wurfl_capability’
May 8th, 2008 at 1:59 am
Works like a charm after applying the two little fixes from Tom and S. Woodside.
Thank you very much for this!