...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.
- lodash-rails - LoDash is very helpful in adding enumerable functions to javascript and in most cases of Rails applications, CoffeeScript.
- local_time - This is a gem that includes a view helper and javascript helper to display relative time (i.e. 'updated 2 minutes ago'). Not only will it format the string, but will update the string on the client side as time goes on.
- 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 %>
...would become
- 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?
Top comments (15)
Very nice list!
Here are a few extras which I use:
Thatβs a solid list of suggestions there. Iβll have to check out contracts. Donβt think I have seen that before!
pry-rails
I'm a
puts
debugger :-|Related - byebug
I 2nd this.
Useful for me:
oj
,redis
,puma
,better_errors
,pry-byebug
,pry-rails
,pry
,wannabe_bool
:)Thanks for sharing.
Nice! I also use
database_cleaner
andfaker
on tests environment.This is a very helpful list. Thanks Rob!
Thanks :D very helpful
Catch errors early with Contracts:
Thanks for this. Really helpful list.
I've been using Ruby on Rails for 5 months now, and it still amazes me the amount of Gems to choose from. Thank you, from a newbie, for listing all of these out, Rob. Appreciate it!
I always use decent_exposure to make my controller even more lean (and not using instance variables)
Interesting gem. It's a little too abstracted for my taste, but I could see it's usefulness.