10 Gems in Ruby that you will love

Let's go back to basics with Ruby on Rails and see some of the Gems that we use everyday at skcript. #StartWithSkcript

Karthik Kamalakannan

Karthik Kamalakannan

10 Gems in Ruby that you will love

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 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

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 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

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 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

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

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

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

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 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!

Last updated: January 23rd, 2024 at 1:50:36 PM GMT+0

Subscribe

Get notified about new updates on Product Management, Building SaaS, and more.

Skcript 10th Anniversary

Consultants for ambitious businesses.

Copyright © 2024 Skcript Technologies Pvt. Ltd.