10 Gems in Ruby that you will love

On , by

After one month of coding on Ruby On Rails, I found these gems to be super useful. Here is the curated list of my favorite gems which can help you write better code and provide you with multiple purposes and solutions.

  1. Annotate
  2. Rubocop
  3. Rspec
  4. Factorygirl
  5. Faker
  6. Paginate
  7. Devise
  8. HTTParty
  9. Whenever
  10. Sidekiq

Annotate#annotate

Annotate adds the schema of a database table to the corresponding model file. All you have to do is type “annotate” in your terminal. To install the gem add the following to the Gemfile of your Rails app,

group: development do
   gem ‘annotate’
end

To install globally on your device, just do

gem install annotate

To annotate your model files, just type, annotate In your project directory.

Find out more: https://github.com/ctran/annotate_models.

Rubocop#rubocop

This gem is a perfect fit for beginners. As I’m also a beginner it helped me a lot. Rubocop not only reports the problems in your code but also automatically fixes it.

It has many other cool features like autocorrect.

To install the gem, just do gem install rubocop.

To audit your project, just type, rubocop in your project directory. To autocorrect use, rubocop -a.

Find out more: https://rubocop.readthedocs.io/en/stable/

Rspec#rspec

Rspec is one of the best tools for testing your code. You can write various test cases for your applications and test them with rspec.

You can install rspec by adding

gem ‘rspec’ in our project Gemfile.

To run your test cases, just type, bundle exec rspec

in your project directory.

Find out more: https://rspec.info

Factory Girl#factory-girl

Factorygirl is used to create mock models so that you don’t have to initialize objects in each of your test cases. Factorygirl can be combined with rspec to makes tests easier and efficient.

You can install Factorygirl by adding

gem ‘factory_bot_rails’ 

in our project Gemfile.

Find out more: https://github.com/dscape/factory_girl_rails

Faker:#faker

Faker reduces most of your work when you test using Factorygirl or Factorybot combined with Rspec. Faker can generate a variety of email ids, passwords, usernames and more.

You can install faker by adding

`gem ‘faker’`

in our project Gemfile.

Find out more: https://github.com/stympy/faker

Paginate#paginate

Almost every page in a website needs to paginate. In order to make the task easier, Rails has this great gem called “will_paginate”.

You can install will paginate by adding

gem ‘will_paginate’

in our project Gemfile.

This creates a “.paginate” scope for all your models that loads database queries page by page.

Find out more: https://github.com/mislav/will_paginate

Devise#devise

In a web application, one of the most important components are sign in, sign up and sign out.

To set up these components easier, just use Devise.

You can install devise by adding

gem ‘devise’

in our project Gemfile.

Find out more: https://github.com/plataformatec/devise

HTTParty#httparty

In some cases, we will need to access data from a third party API. To make HTTP calls, use HTTParty.

You can install HTTParty by adding

gem ‘httparty’

in our project Gemfile.

With HTTParty, you can make GET, POST, DELETE and more calls to third party endpoints.

Find out more: https://github.com/jnunemaker/httparty

Whenever#whenever

Using the Unix Cron to setup scheduled jobs has never been easier than with Whenever.

gem ‘whenever’

in our project Gemfile.

With this gem, you can setup cron jobs directly in your Rails app. All cron jobs will have access to your models and logic, and communicate with Unix Cron!

Find out more: https://github.com/javan/whenever

Sidekiq#sidekiq

Sidekiq is used for background processing. It is useful when handing time consuming tasks like computation, sending emails or generating reports. If these tasks are run during session there is a possibility of a 408 request timeout.

gem  ‘sidekiq’

Sidekiq uses Redis, so make sure to have that installed!

Find out more: https://github.com/mperham/sidekiq/wiki/Getting-Started


Now you know about some of the best Ruby gems and their functionalities. So what are you waiting for? Start using gems frequently and make your applications work amazing. Happy coding!

Share this article on Twitter or LinkedIn
Previous Blog Post: 11 Questions you should ask before building your own chatbot in 2019.
Subscribe to Sudo vs Root

Our newsletter rolls out every month. No fluff. Pure content.

Comments and Discussions
Skcript https://www.skcript.com/svr/10-gems-in-ruby-that-you-will-love/ https://www.skcript.com/svrmedia/heroes/10-gems-in-ruby-that-you-will-love@1.5x.png

Connect with Skcript Global

In 72-hours, your business gets a clear blueprint of what we can do for your organization.

Contact us

Follow us on Twitter / LinkedIn / Instagram