DEV Community


Ruby Gems - My Favorite Ones

matiascarpintini profile image Matias Carpintini Updated on ・4 min read

A gem is a good or bad depending on how well it solves the problem are designed for. And this is why the order below is stupid, there are not some better than others in this top, because their solve different problems between.

ADVICE: Avoid filling your applications with many gems.

Some of the ones listed below can be replaced by a bit of self-made code. In this way you create more durable applications over time.

Still, they are very necessary when we have little time and we are hardly validating a product. And that's the reason why I decided to include them.

1. Devise

Obvious, how not to include this gem. A classic. For those who do not have much time in Rails, Devise gives you everything you need for user authentication. Registration, sessions, password reset, etc.

It is really easy to use.

More info.

2. Paperclip

A management for uploading images with the ActiveRecord. Also very easy to use, with 1 simple line of code (literal) you can already have attachments in your resource.

More info.


Among other things, it provides us with the API client to upload the previous paperclip images to AWS S3, also in a super simple way.

More info.

4. Annotate

It is responsible for commenting on our models with the fields of said table in db. Very useful if you handle large data structures.

Something like (app/models/post.rb):

# == Schema Information
# Table name: posts
#  id                 :bigint           not null, primary key
#  title              :string           default(""), not null
#  body               :text             default(""), not null
#  created_at         :datetime         not null
#  updated_at         :datetime         not null
#  user_id            :bigint           not null
# Indexes
#  index_posts_on_title    (title) UNIQUE
#  index_posts_on_user_id  (user_id)
# Foreign Keys
#  fk_rails_...  (user_id =>
Enter fullscreen mode Exit fullscreen mode

More info.

5. Faker

It is used to generate random data, such as names, surnames, telephone numbers or emails. For those who spend more time testing, this gem may be a must. Fill your seeds with 0 effort.

# Random Book Title
Faker::Book.title #=> "The Odd Sister"
Enter fullscreen mode Exit fullscreen mode

More info.

6. Sidekiq

Sidekiq helps us to process tasks in the background in an efficient way. Actually, I already talked about Sidekiq before. I leave the article in case you are interested.

More info.

7. Will paginate

Another classic. We will pass a resource to will_paginate and it generates the pagination according to what we indicate.

More info.

8. Truemail

May be complementary to Devise. She validates and ensures that x email exists. A great little help to deal with spam or user errors.

More info.

9. Draper

Rails (and his community) respects his philosophy a lot, a great design pattern is decorators.

This adds an additional logic representation to the objects.

Imagine you have a User model, that user has name and surname, now, instead of doing + "" + user.surname in the view, you can create a decorator for User, that inside has a full_name method, receive a User and return the full name.

A simple but representative example. Don't store logic in your views! Draper helps you implement it in a super simple way.

More info.

10. Friendly id

Through the slugs concept it lets you create pretty URLs and work with human-friendly strings as if they were numeric ids.

Example (app/models/post.rb):

extend FriendlyId
friendly_id :title, use: :slugged
Enter fullscreen mode Exit fullscreen mode

Normally the URL to access this view would look something like http://localhost:3000/posts/1, but friendly_id takes the title (for example) and use it, instead of post id. Result, http://localhost:3000/posts/post-title-example

More info.

11. Chartkick

I have special affection for this gem. With it we can create graphics in a super fast way, in a single line of code.


<%= line_chart User.group_by_day(:created_at).count %>
Enter fullscreen mode Exit fullscreen mode

Returns something like:

More info.

12. Reading time

It estimates us how long it can take the user to read certain text. Like, '3 minutes of reading'. It can be useful for a blog, to display it in top of the article body.

More info.

13. Impressionist

Count user views and impressions. How also which user saw such a thing and how many times.

More info.

14. Money

No matter what you're building, if you handle money type data, this gem cannot be missing. Save multiple currencies and do the conversion.

More info.

15. Route translator

Translation is a broad topic, but for some reason routes are rarely touched on and that also ends up impacting the user experience. This gem will do just that, translate the routes of your application as you indicate.

More info.

16. CanCanCan

Another gem that can be complementary to Devise. CanCanCan allows us to authorize or not our users in certain actions. We establish roles under the concept of ability. Highly recommended.

More info.

Is it all, do you know any other gem that has solved your life and is not very popular? Tell us! 👋


Editor guide