Rails 3: Fully Loaded

It’s been close to a year since Rails 3 came out and I’ve had the pleasure of working on several Rails 3 projects since its release. Some existing gems became irrelevant with the release of Rails 3, while others lived. Additionally, we’ve seen many new gems come to life. I’d like to share a stack of gems that I’ve been using this year. Hopefully they will give people a bit of help while developing a new Rails 3 app.

Most of these gems have good documentation on their project wiki (every great gem should be well documented, right?), so I won’t go into great detail about the mechanics. Instead, my aim is to introduce you to some of the gems I find most useful and separate them into meaningful categories, as a sort of reference guide.

Here we go:

» Authentication

The above two are really amazing gems for speeding up your authentication. Yes, I love both of them in different cases: ideally, OmniAuth is better for applications which want to support multi-provider external authentication, which is why I’ve just added OmniAuth into the RefactorMyCode Rails 3 branch to take advantage of its auth benefits. Devise is totally powerful enough for the classic authentication case. However, if you have too much business logic inside your login/registration/auth flow, you definitely need to make your own authentication.

» Access Control

Ryan is a star in the Rails world, so naturally his CanCan gem is really popular, but with good reason: it does really powerful authorization. However, declarative_authorization is also a good option. In fact, Ryan mentioned CanCan was inspired by declarative_authorization.

» Views/Page and Admin Scaffold

From a front-end perspective, I suggest you might want to try the above gems to speed up and simplify your UI design process. For example, rails_admin gives you a nice interface to manage your application’s data.

» Quick SNS

These gems will allow you to prototype the basic functionality of your application quickly without having to worry about creating everything from scratch – so you can focus more attention on the meat of your application instead of the nuts and bolts.

» Form and Related Tools

Most of the above gems are famous through RailsCasts. There are two pairs of options here: simple_form and formtastic or paperclip and carrierwave. I like all these solutions, and you should pick the one that fits your project. If you want to know the differences between each pair, get more details on their wiki 🙂 tiny_mce is an HUGE gem for rich editing; I list it here to remind you that it exists, but I recommend you get the WYSWYG via a JS lib like CLEditor – it works gracefully.

» Search Solutions

In regards to search in Rails, I bet there are some strong opinions out there. I want to split these gems into two types: Object-based searching and Full-Text searching. I highly recommend you use meta_search and/or meta_where for object-based searching because it can convert your form params directly to a search solution which is super convenient. Full-Test searching depends on your use-case, but all these three gems (thinking-sphinx, acts_as_indexed, sunspot) are great.

» Pagination

Yeah, you can use will_paginate in Rails 3, but I will suggest you should give kaminari a try, that’s really cool.

» Background Work

These are two projects that accomplish basically the same thing. There is a post that introduces resque clearly here. In the post, the Github staff mentions their brief history of doing background jobs and they do a good job at highlighting the differences between the two.

» Status Machine

I like to use workflow a bit more than state_machine, since it’s more natural to me. You definitely need one status machine to control your stable flow stuff, such as a registration flow status or a wizard-like features.

» Rack API framework

This gem is for adding REST-like APIs to your Rails/Sinatra application. Michael gave an awesome presentation at RubyConf2010 on Grape; I recommend watching it to see the greatness of Grape for yourself. I believe you will fall in love with it.

» Memcached Client

These two gems are actually mainly written by one same author Mike Perham. He mentioned that Dalli is a high performance pure Ruby client for accessing memcached servers. It works with memcached 1.4+ only as it uses the newer binary protocol. It should be considered a replacement for the memcache-client gem. The API tries to be mostly compatible with memcache-client with the goal being to make it a drop-in replacement for Rails.

» Deployment and Monitoring

I am not a system administrator, so I can’t speak with any authority on this. That said, I do find these three gems come in handy with deployments and monitoring.

» Cron job and Backup as a Pro

These two gems are my favorites! Before I knew about these, I had to write complex and stupid scripts to do backups that I was not familiar with. Cron job is also a pain if you are not a system administrator. Now time changes and you, as a Ruby programmer, can do the cron job and backup in the Ruby way, surely as a PRO. 🙂

» Testing Gracefully

Testing is always important, and with the popularity of testing practices like TDD and BDD you have to own your super gun to play. These gems can help you out, although I didn’t cover all the different levels of testing with these gems. But I will say, rspec is my favorite framework for testing, and factory_girl and faker are good supports. Anyway, test by your own way.

» Toolkit

There are many handy gems which will give you convenience and power. Take the above four as examples: “Ruby-Debug” lets you easily check your running application’s context at specific program points; “Hirb” displays your AR items conveniently in a table view in console; “Cheat” brings tons of other gems’ manuals into your terminal window for easy reference and; “Rails-Settings-Cached” is for global configurations in Rails 3 applications. Yeah, throwing the brick out is to meet your GEMS.

How to find great gems?

First, you need to follow Ryan’s railscasts; he is good at introducing new stuff via video. Second, you can go through the GemFile of a great open source project that you love – this is definitely the best way to come across valuable gems. Third, just subscribe to github ruby trends to know what’s going on in Ruby/Rails community. There are also some other good sites, like rubygems and railsplugins, where you can find useful gems with some poking around.

I originally shared this topic with all of the Intridea East Team members during our weekly Friday Tea-hour. You can find the PPT here. I wanted to share the list with more people, so I turned to our blog for that purpose. I’m sure I missed many valuable gems, so please share your thoughts in the comments!