My Favorite List of Gems for Ruby on Rails MVC Framework

I have been developing Ruby on Rails applications since Jan. 2013. I am simply amazed with the huge collection of available Ruby gems (packaged libraries) that help in extending Ruby on Rails application’s functionality.

At the time of writing this post, there are about 80,000 (approx.) gems in RubyGems. Because there are huge number of gems and services readily available out there, it becomes increasingly difficult for beginners who have just made an entry to Ruby on Rails world to find the best ones out there to suit their application needs. Its all so confusing and time-consuming for the beginners (including myself when I was a newbie) to wade their way out and to decide on a gem or to re-invent the wheel(intentionally or unintentionally).

The purpose of this blog post is to share few of my most favorite Ruby gems that have helped me tremendously while developing the Ruby on Rails applications.

  1. DEVISE (AUTHENTICATION)

    Most Ruby on Rails applications require user registration and authentication mechanisms. Developing these from scratch requires a lot of time and effort – thankfully, there’s Devise. Using the Devise gem, you can set up a full-fledged user authentication system within minutes. It is a flexible authentication solution for Rails and it provides services like Database Authenticable, Omniauthable, Confirmable, Recoverable, etc.

  2. CANCANCAN / PUNDIT (AUTHORIZATION)

    Almost every web application with an authentication system needs an authorization mechanism to complement it, in order to introduce user-access-level security with restrictive access to some users. It’s a tie and I can’t just love one gem over other when it comes to decide the best gem for Authorization. CanCanCan (Continuation of CanCan gem originally developed by Ryan Bates) is a simple authorization solution for Rails which is decoupled from user roles. All permissions are stored in a single location. On the other hand, Pundit provides a set of helpers which guide you in leveraging regular Ruby classes and object oriented design patterns to build a simple, robust and scaleable authorization system.

  3. PAPERCLIP (FILE ATTACHMENTS)

    Many web apps require the user to upload images and other files for storage and processing. Paperclip is a cleanly abstracted Ruby library that reduces the complexity of file uploading and processing. Using Paperclip with an external storage service such as Amazon S3 or RackSpace CloudFiles allows you to scale your application’s files and codebase independently. UPDATE: I have recently moved couple of projects to CarrierWave gem which is a lot more flexible than Paperclip.

  4. SIMPLE_FORM (FORM)

    Rails forms made easy. Simple Form aims to be as flexible as possible while helping you with powerful components to create your forms. The basic goal of Simple Form is to not touch your way of defining the layout, letting you find the better design for your eyes. Most of the DSL was inherited from Formtastic, which we are thankful for and it makes you feel right at home. It’s far better than the default Rails form helpers.

  5. BETTER_ERRORS (DEBUGGING)

    This gem is a life saver. Better_Errors gem has saved me lots of time while debugging the Rails application bugs. It replaces the standard Rails error page in a clear and visually appealing way along with much more detailed debug information. It also provides REPL for live interaction with the code. When you add this gem to your app it’s important to place it in the development group so that we don’t show details of any of the application’s errors in production and allow a malicious user to get some critical information via REPL or error messages.

  6. WILL PAGINATE (PAGINATION)

    As your application begins to grow in terms of number of posts you might want to add pagination to break it up a little. When it comes to pagination Will_Paginate is by far the reigning champ and fairly recognizable gem out there. It works well right out of the box. UPDATE: I am also very much impressed with Kaminari gem which is a Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Rails.

  7. DELAYED_JOB (BACKGROUND JOB SCHEDULING)

    Delayed_Job is a ruby gem which is used to asynchronously execute the tasks as a background process in Rails environment which in turn increases page rendering speed. It was originally extracted from Shopify and is a robust, stable solution available out there. If your application deals with long running tasks such as image processing or emailing newsletters to a huge list of recipients, then it would be wise to move these processes in the background without annoying the users.

  8. FACTORY_GIRL_RAILS (TEST DATA)

    Factory Girl is my favorite gem for making test data. Factory_Girl replaces fixtures in tests and Factory_Girl_Rails gem provides Rails integration for Factory_Girl. In other words, its “a library for setting up Ruby objects as test data” or more precisely it is a fixtures replacement. This way, you won’t have to worry about keeping the fixtures up-to-date as you change the data model. It provides support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.

  9. RSPEC + CAPYBARA (TESTING: BDD)

    RSpec is just a ruby library for automated testing, just like Test::Unit or Minitest. It gives Behavioral Driven Development(BDD) for Ruby. The thing with RSpec is that it uses very special syntax and method names to make the test code read like English prose. This is done to give the reader a better understanding of the test code and make it easier to read. Capybara helps you test web applications by simulating how a real user would interact with your app. Capybara does an excellent job of writing user integration tests.

  10. FRIENDLY_ID (SEO)

    A perfect gem to make our page URL Search Engine Optimization (SEO) friendly. And it becomes more important for us nowadays because everyone want their website to be SEO efficient. Friendly_Id is the “Swiss Army bulldozer” of slugging and permalink plugins for Active Record. It lets you create pretty URLs and work with human-friendly strings as if they were numeric ids.

All of the above listed gems are my favorite ones that I have included in almost all of my Rails applications. I call them my Top 10 (would love to make Top 15… may be later) must-have gems. They represent the best options to develop in an Agile and DRY manner and to achieve solutions to complex problems in the shortest time possible.

Comments are closed.