27 Ruby Gems I use in almost every project
Rob Race Mar 21, 2017
...and pretty much can't live without
The Rails community thrives on its open source gems. Implementing a well written, well tested and vetted gem can make the difference between days and weeks of development of new features.
Not every gem is great, but I wanted to share a list of gems that I have used on nearly every recent project I have worked on.
Note: This article is an excerpt from a chapter in my upcoming book Building a SaaS Ruby on Rails on Rail 5. The book will guide you from humble beginnings through deploying an app to production. If you find this type of content valuable, the book is on pre-sale right now!
Here are the 27 gems:
- aasm - Formerly, acts_as_state_machine. This gem will help you handle state management on complicated or heavily branched workflows. Particularly when you are dealing with Stripe or other objects that may go through a pipeline of stages.
- devise and devise_invitable - Devise is the authentication library most used in Rails for the past few years. While there are some up and coming libraries to provide authentication services, the support around Devise and it's ease of use make it great to move quickly on your SaaS application. Devise Invitable is an add-on gem that will allow you to have an invitation system to have users invite other users to your application.
- rolify and cancancan - Rolify allows the application to assign roles such as User or Admin on a User object. Then CanCanCan allows you to take those roles and apply authorization policies.
- paper_trail - This will allow you to set up audit logs on particular models so you can see what users made a change. Using that information to be displayed within your application in an activity log or just used as a way to troubleshoot changes.
- ranked-model - Allows quick ordering and sorting of sibling elements. Instead of using a sequential position integer, it uses big numbers to sort faster.
- bootstrap-sass - Allows you to use the Bootstrap HTML/CSS framework to quickly build a usable interface for the application.
- friendly_id - Used in obfuscating the auto-incremented primary ID used in rails objects from the URL.
- slim-rails - Instead of using HTML markup with Ruby code embedded, Slim is another templating language that allows you to write simple markup, without the need for closing tags. For example:
<%- if @user.admin? %> <h1>Welcome back admin</h1> <%- else %> <h1>Welcome back pal</h1> <%- end %>
- if @user.admin? h1 | Welcome back admin - else h1 | Welcome back pal
- Sidekiq - This gem allows you to run background jobs, backed by a Redis queue. Instead of running tasks like sending emails on the main request loop. You can drop it into a Sidekiq job to run in the background.
- kaminari - This gem handles pagination and it's edge cases. It also includes templates that already work with Bootstrap.
- paperclip and aws-sdk - Combined these two gems will allow you to upload assets such as avatar images through your application into AWS S3.
- money-rails - This will help standardize around common issues found when calculating money as well well providing a few template helpers.
- ransack - A search abstraction that will allow you to create simple forms that can search through tables. Such as a search form on a users index page.
- slack-notifier - Simple Slack API integration tool to quickly send a message to a Slack Webhook. Tiy can use this to send notifications to your own Slack when a new user signs up or in other areas. You may use more in-depth gems if more than Webhook integrations are needed with Slack.
- premailer-rails - This helps with CSS inclusion into mail templates. Gmail will commonly break email templates based on how they can ignore included CSS. This gem automatically merges styles into the markup tags to work in Gmail.
- griddler - This tool allows you to parse email received through a mail sending API. I have used this gem with its Sendgrid companion gem, but you can choose other email providers as well.
- rollbar - This gem allows you to send exceptions to a third-party exception aggregator. Otherwise, you would need to set up your own exception notification process or spend all your time watching Rails' logs.
- rspec-rails, factory_girl_rails, simplecov - I personally like to use RSpec over the default Rails test framework. I find it easier and quicker to reason about model factories over fixtures for the more complex model associations. SimpleCov is an easy way to keep track of your test coverage.
- letter_opener - This gem will open mail in the browser instead of attempting to send mail in the development environment.
- rack-cors - This gem will help set up CORS rules. This will be of use if accessing JSON requests from domains that are not the current Rails' app configured domain name. This is helpful if at any point a request from front-end code is sent to your Rails application.
Those are my pick for gems, what are yours?