HomeRamblings  ⁄  ProgrammingRuby Language

Gems you should consider for every Rails projects

Published: January 17, 2014 (about 6 years ago)
Updated: almost 5 years ago

Ruby on Rails provides a lot of great functionality out of box, but there are a few gems I almost always add to my new Rails projects. Here are some of those gems I practically cannot live without.

HAML Templates

gem 'haml'

I know many developers who say “HTML is a perfectly good DSL for HTML” and I used to follow in this mantra myself until one day I had to work on a new Rails project that already had HAML in use. There’s a lot to be said for “less is more” when the clutter of punctuation and inconsistently indented code is replaced by the stripped down, well-indented code. When you inherit a ERB-based project that is full of conditional flow and Ruby code embedded in the view files, you really start to appreciate the power of HAML as a template. While you should not be putting logic in your views like this, too many developers do it anyway. With the HAML gem installed, you can run html2haml against any existing *.html.erb file and get the HAML-ized equivalent.

Quiet Assets

gem 'quiet_assets'

Tired of seeing all those logger messages for every little thing coming out of the assets pipeline? Turning the assets logger off gets you back to the good ole days of focusing on what matters most: the SQL and the controller/action that is rendering and what parameters were fed to the beast.


gem 'rspec-rails'

There’s nothing wrong with the UNIT::Test framework Rails gives you out of box, but its not my style. I use TextMate and I especially like the integration of running rspec from within TextMate. The command line is largely reduced to printing just the dots, but if I run the tests in TextMate, I see the full story of the tests that are running nicely nested and colorized, which helps me find gaps in my tests as well as quickly jumping to the file and line in question by clicking the convenient links the editor puts around the failing specs.

Guard and Spork

gem 'spork'
gem 'guard'

While on the topic of testing, two different gems that help you test more efficiently is Guard and Spork. Guard is configured to watch your Rails project files, both in the app folder and in the test/spec folder and when they change, automatically reloads and runs the related specs. Guard can even be configured much like a continuous integration server to run all tests whenever the specs you’re working on passes 100% of its tests. With OS X environments, its easily configured to post its results via Growl so your eyes stay more on the code and less on the terminal window. Spork is the other testing facilitator and often becomes a necessary evil once a Rails project grows beyond a certain size. No matter how much effort you put into writing fast, optimal tests, large projects eventually take a long time to fire up and run. Spork works by essentially loading up the Rails environment and then spinning off copies of the loaded app to run the specs, thus bypassing the startup penalty.


gem 'capistrano'
gem 'capistrano-ext'
gem 'rvm-capistrano'

When it comes to deployment, the two best options are rspec and Capistrano. If you’re the sole developer developing and deploying on a project, then wrapping up your deployment commands into a couple rake tasks around a simple rsync call is all you need. But if you’re working in a team environment and multiple developers are continuously deploying, then capistrano is the goto deployment tool of choice. Its been around since the beginnings of Rails popularity and has many extensions (as gems) that help making setting up your next deployment workflow a breeze to get right. The capistrano-ext gem gives you different stages (staging, production, etc.) while the rvm-capistrano gem helps you manage your ruby environment on the server.

Better Errors and Error Notifications

gem 'better_errors'
gem 'exception_notification'

Better Errors is more than just a pretty improvement over the default Rails session/error dump pages. It provides a rich, interactive layout of the error call-chain and even a ruby variable inspection prompt right in the browser. And much like the rspec integration with TextMate, you can click the file with line number to jump right to the breaking code in TextMate. Exception Notifications enables Rails to send exception reports to your email so the next time Rails says “Something went wrong…”, somebody really is getting an email with the error report to investigate.

Faker and placehold.it

gem 'faker'

In the spirit of rapid prototyping and wireframing for your new customers, the Faker gem along with http://placehold.it can help you to rapidly build pages with filler content. With faker installed, you can generate add seed data or simply produce Lorem Ipsum at will with Faker::Lorem.paragraph, Faker::Lorem.sentence, etc. Placehold.it is a web-service, not a gem that will produce images of any given size with the sizing data shown on the placeholding image. I typically add a image_placeholder(width, height) helper to the application_helper that will render the appropriate IMG tag.

Twitter Bootstrap


If I’m doing the front-end styling and design, then I can’t live without good CSS grid system and Twitter’s Bootstrap 3.0 is my main go-to. I don’t typically reach for any of the twitter bootstrap gems because too much has been changing with Rails 4 coming out and the existing gems not supporting the sprockets asset pipeline quite correctly followed by Bootstrap 3.0 coming out just as those gems started getting it right with Rails 4. Once the dust settles, I’m sure one of the Bootstrap gems will take the cake, but for now, I just pull down the complete bootstrap and drop it into my assets pipeline myself.


Give these gems a try next time you’re firing up a Rails project or experimenting. From coding to testing to deployment these gems go a long ways towards making your overall development easier and more efficient.

comments powered by Disqus