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:
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
- CanCan (https://github.com/ryanb/cancan)
- declarative_authorization (https://github.com/stffn/declarative_authorization)
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
- compass (https://github.com/chriseppstein/compass)
- haml (https://github.com/nex3/haml)
- sanitize (https://github.com/rgrove/sanitize)
- rails_admin (https://github.com/sferik/rails_admin)
- web-app-theme (https://github.com/andreferraro/web-app-theme)
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
- acts-as-taggable-on (https://github.com/mbleigh/acts-as-taggable-on)
- has_friends-rails3 (https://github.com/rrouse/has_friends)
- acts_as_favable (https://github.com/yorzi/acts_as_favable)
- thumbs_up (https://github.com/brady8/thumbs_up)
- acts_as_commentable (https://github.com/jackdempsey/acts_as_commentable)
- profanity_filter (https://github.com/intridea/profanity_filter)
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
- simple_form (https://github.com/plataformatec/simple_form)
- formtastic (https://github.com/justinfrench/formtastic)
- formtastic_datepicker_inputs (https://github.com/demersus/formtastic_datepicker_inputs)
- tiny_mce (https://github.com/kete/tiny_mce)
- paperclip (https://github.com/thoughtbot/paperclip)
- carrierwave (https://github.com/jnicklas/carrierwave)
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
- meta_seach (https://github.com/ernie/meta_search)
- meta_where (https://github.com/ernie/meta_where)
- thinking-sphinx (https://github.com/freelancing-god/thinking-sphinx)
- acts_at_indexed (https://github.com/dougal/acts_as_indexed)
- sunspot (https://github.com/outoftime/sunspot)
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.
- kaminari (https://github.com/amatsuda/kaminari)
- kaminari_themes (https://github.com/amatsuda/kaminari_themes)
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
- delayed_job (https://github.com/collectiveidea/delayed_job)
- resque (https://github.com/defunkt/resque)
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
- workflow (https://github.com/geekq/workflow)
- state_machine (https://github.com/pluginaweek/state_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
- memcache-client (https://github.com/mperham/memcache-client)
- dalli (https://github.com/mperham/dalli)
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
- capistrano (https://github.com/capistrano/capistrano)
- cap-recipes (https://github.com/nesquena/cap-recipes)
- god (https://github.com/mojombo/god)
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
- rspec-rails (https://github.com/dchelimsky/rspec-rails)
- factory_girl_rails (https://github.com/thoughtbot/factory_girl_rails)
- faker (https://github.com/yyyc514/faker)
- watchr (https://github.com/mynyml/watchr)
- autowatchr (https://github.com/viking/autowatchr)
- database_cleaner (https://github.com/bmabey/database_cleaner)
- mail_safe (https://github.com/myronmarston/mail_safe)
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.
- ruby-debug (https://github.com/mark-moseley/ruby-debug)
- hirb (https://github.com/cldwalker/hirb)
- cheat (https://github.com/defunkt/cheat)
- rails-settings-cached (https://github.com/huacnlee/rails-settings-cached)
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!