We build Web & Mobile Applications.

< All Articles

Rails plugin round-up

Over the last year we’ve been involved in a wide variety of projects using Ruby on Rails and in that time we’ve had to use many different plugins. As you’d expect some have been better than others, so here’s a quick round-up of a few that I have found particularly useful.

Global positioning with Graticule and acts_as_geocodable

The Graticule gem, along with its Rails companion the acts_as_geocodable plugin, developed by the guys at Collective Idea provides a simple way to add geocoding to your Rails application.

I first made use of Graticule and acts_as_geocodable last July when I was putting together the Activity Centre Directory for Fat Face. I considered using the (often recommended) YM4R plugin but it offered too much functionality as I only wanted a geocoder and intended to roll my own Google Maps code. I’ve since used Graticule and acts_as_geocodable with the Google Maps geocoding API in a number of projects and think it’s great.

Veracious validation with validates_email_veracity_of

Although Rails includes a number of validation helpers there are some that you’d really expect to be part of a web development framework that are strangely missing. Email address validation is one omission that seems particularly strange given that most websites are likely to involve user input of email addresses at some stage.

A couple of years ago I wrote a validation class for a site coded in PHP that checked both the format of the address (using a regular expression) and that the DNS entries (MX or A records) existed for the domain and it really helped to cut down on the number of incorrect email addresses entered by users.

I wanted something similar for Rails and after a little bit of searching came across the validates_email_veracity_of plugin by Carsten Nielsen at Rails.Savvica. It’s a grand name for a grand plugin: I especially like the addition of a white list so that time isn’t wasted checking DNS records for known domains, such as googlemail.com or yahoo.com.

Existential thoughts with validates_existence

Another notable absence from the standard Rails validators is handled by Josh Susser’s validates_existence plugin. Newcomers to Rails often mistakenly believe that validates_associated or validates_presence_of will check the existence of an associated record but be warned: they don’t.

Josh’s plugin does involve an extra SQL query in order to determine if an object’s record exists, which you should remember when you’re tweaking your application’s performance, but it does add an extra layer of protection from your users doing something stupid.

File upload attachment_fu

Rick Olsen’s attachment_fu plugin provides powerful yet easy to use support for file uploads and image processing. I’ve not used the Amazon S3 or database storage options but have used both the RMagick and ImageScience image processors with good results.

An excellent starting point for using attachment_fu is Mike Clark’s File Upload Fu blog entry which tells you pretty much all you need to know to get going. My only real complaint with attachment_fu is that its validation error messages leave a lot to be desired (Size is not in list anyone?) but luckily Toolman Tim has a solution that I’ve found to work very nicely.

Time is running out for TzTime

The final plugin I was going to mention was TzTime that, in conjunction with the TZInfo Timezone plugin and TZInfo gem, gives Rails a better shot at handling time zones (though it is a bit worrying that it takes two plugins and a gem to do so).

However I discovered today while mooching through the Rails trac that the future for Rails time zones is looking a little brighter thanks to the addition of the TimeWithZone class into the Rails core. If you’re just starting a new Rails application that needs to be time zone aware then it is probably worth running on edge to take advantage of this new class rather than having to mess around too much with plugins. If you do decide to use TzTime then be warned that the ActiveRecord helpers aren’t that helpful: you’ll probably want to apply some of these patches to make things work more reliably.

Updated on 15 October 2015
First published by Rob Anderton on 04 February 2008
© TheWebFellas Limited 2016
"Rails plugin round-up" by Rob Anderton at TheWebFellas is licensed under a Creative Commons Attribution 4.0 International License.