Blog / Random thoughts and musings.

 

  • on July 13, 2009 -
  • computing
  • |
  • Comments Off on Essential Ruby on Rails plug-ins and gems

Essential Ruby on Rails plug-ins and gems

Now that I’ve been using Rails for a while, I’ve accumulated a few gems and plugins that I end up using over and over, so I thought I’d share a little about each.

haml and sass

I was sold on Sass from the first few minutes I used it. Sass lets you write CSS using a simplified abstraction format, and compiles your sass code into CSS. Best of all, it can be used without Rails (or Ruby), so I’ve been using it with static web pages as well. Here’s an excellent example from the sass web site:

haml-sass

Haml does the same for HTML. It took me a little longer to get used to, probably because it’s actually a replacement for HTML and Embedded Ruby (ERB). Haml really cuts down on the amount of typing needed to generate HTML, auto-closes tags (based on indentation), and makes it far easier to see the structure of your document. This snapshot from the haml page is a great demonstration:

haml

friendly_id

This extends Rails’ RESTful resources by making URLs look “friendlier”, using a user-specified attribute of a model instead of the auto-generated numeric ID. In other words, by simply adding a statement like has_friendly_id :name to a users model, friendly_id converts URLs from http://my.site.com/users/17 into the much nicer http://my.site.com/users/mike.

Authlogic

This is the leading user authentication framework for Rails. It you need to allow users to register, sign in, change passwords, use OpenID, user LDAP, etc., this is the plug-in for you. It takes some time to learn how to integrate it, since each web site’s implementation is going to be a little different.

mislav-will_paginate

This makes it dead simple to take a model with many records, and display it in pages, where you can control how many are displayed per page, and the style of the page links:

pagination

thoughtbot-paperclip

I’ve researched and tried many file upload/attachment gems but Paperclip is the one I settled on. It seems to be the most actively maintained, and one of the most flexible. File uploading is still not as easy as it should be, especially if you want to provide feedback during upload (usually via a Flash plugin) or allow multiple attachments to a model (usually with an associated polymorphic upload model). Paperclip doesn’t do these things out of the box, but it’s possible to wrangle it into submission…

unobtrusive_date_picker

These days there’s no reason to make your users select a month, day, and year from three separate drop-down boxes, or type a date in some pre-determined format. This plug-in automagically adds a pop-up calendar to your date selection input fields.

date-picker

jRails

When I started learning Javascript a few years ago, it was a huge pain in the neck. I quickly came across Prototype, which made my life much easier. Before I got too far along with that however, I found jQuery and fell instantly in love. This was clearly the way Javascript programming was meant to be. I used it for everything. Then last year when I started learning Rails, I was a little disappointed to find that the javascript library built-in to Rails was Prototype. Fortunately, others apparently had the same complaint, and created JRails, which integrates jQuery with Rails.

Others

There are a few other gems and plugins I use, but not as frequently. They include: Maruku, acts_as_audited, mechanize, and hpricot.

Am I missing out on any must-have gems or plug-ins? Let me know in the comments!

 

Comments are closed.