11 must-to-know gems for Ruby

Sofia Basanta
Unagi
Published in
4 min readMay 3, 2021
Illustration by Icons 8 from Icons8

There is an old rule in Engineering: Don’t reinvent the wheel. If something is already developed and works well, why do it again? Newton thought something similar: “If I have seen further it is by standing on the shoulders of Giants”.

This philosophy is the one we keep in Unagi. This is the way we code, by enhancing our craft with tools our fellow programmers have made available to us. Well, they are more than tools. They are gems.

For those of you who work with Ruby ♥️, gems might be a common language. If not, here is more information. Although using gems makes our work easier, filling up indiscriminately our application with gems is not beneficial because it can make it slow as well as lose control of what is done. So, how do I choose one gem instead of another one? By its efficiency, simplicity, and effectiveness.

We should carefully choose what gems to use. I would suggest always do some research before picking one. There are no fixed criteria to choose one over the others and usually depends on what you are trying to solve. Not part of this article, but more about this could be found here.

Following, there is a list of eleven gems that made my work easier more than once and I want to share them with you.

Sorcery

A great gem that takes care of authentication in your app. It’s small and simple but it does the work. We could use a well know gem as Devise but most of the time we need a simple authentication system and we don’t really use the other several features that the gem has.

Pundit

This gem allows you to build a simple but effective authorization system. It’s amazingly simple and just using plain old Ruby object (or PORO). I love it!

Draper

Where should I specify how to present something? Inside the Model or in a Helper or both? Draper is your solution, it adds an object-oriented layer of presentation logic, that wraps the model and deals only with presentational concerns.

Pry ByeBug

Pry ByeBug is the combination of two great gems: Pry and ByeBug, and has the advantages of both.
When there is an error in our code, and yes, there will be. It is very useful to know what happens at each step. This gem allows you to add breakpoints to your code just by typing “binding.pry”. When we run the application, it stops at that statement and we can interact from the console, we can ask for variable values, execute functions, just like the rails console. With two simple statements: next or continue, you can execute the next line of code or resume execution. Also, if you don’t know where you stopped, you can always run whereami.

Pagy

Simple, light, fast and efficient gem to paginate. What else to ask for?

Rspec

A key aspect to guarantee the quality of a system is testing. Rspec is a great ally, with a perfect integration with Ruby on Rails. It is a very robust tool and is one of the most used testing frameworks in the Ruby community. If you want to learn more about this topic, I invite you to read: Testing in Ruby: Minitest vs RSpec(Spanish)

Prawn

The best gem for PDF generation. It provides a lot of great functionality: Extensive text rendering, vector drawing, support a variety of fonts, image embedding, security features, and a lot more.

ActiveRecord Import

This is a very powerful gem. It allows you to insert data using ActiveRecord minimizing the number of SQL insert statements. Thanks to this gem we carried an import that usually takes hours to a few minutes.

Capistrano

When we talk about a deployment in Unagi, we talk about Capistrano. This gem is a framework for building automated deployment scripts, one sentence is enough to deploy your app into production.

Audited

The best gem to register a events log into ActiveRecord models. I recommend it because it is simple to use and integrates very well with ActiveRecord models. I think the way it saves the differences and the possibility of leaving a message explaining the change make it really useful.

You must bear in mind that this list is in no way final. When I was studying at the university I used the Devise gem, but now I recommend Sorcery. Today you may use one, but software is always evolving, and new tools are being developed as I write this by peers who just want to make our tasks easier (and have fun in the meanwhile!). That’s the great thing about the open-source community ❤.

And you, what gem do you use for your Ruby on Rails applications? Leave us your comment 💬 and some 👏 if you liked the article.

--

--

Sofia Basanta
Unagi
Writer for

Computer Engineer | Ruby on Rails developer at Unagi