These are the 5 Must Have Gems for Your Ruby on Rails Projects
--
With 133,000+ Ruby Gems in the wild, the Rails community has a library to suit most project’s needs out of the box. However, the wide breadth of options can also make choosing which gems to include a time consuming task. Here are 5 must have gems for Rails projects.
1. Bullet
The Bullet gem helps optimize the performance of your application. It can warn you during development about N+1 queries (see part 1 here), when a model is eager loaded unnecessarily and when a counter_cache would increase your application performance.
2. Rubocop
Standardizing styling of a codebase across multiple developers can be tricky especially as new members are onboarded to the team. Rubocop is a linter for Ruby that can help automatically clean up the code to conform to accepted standards or be tuned to your specific needs. Some examples of Rubocop in action can be found here.
3. Byebug
Who has not written a code similar to the one below and noticed they wanted to see more variables?
class FavoritesController < ApplicationController
def show
puts '***********'
puts my_variable
puts '***********'
render ...
end
end
With Byebug you can instead add the keyword byebug
wherever you want to analyze the code context and it will expose an interactive session that is bound to the context of where it was invoked.
4. Web-Console
The web-console gem exposes an interactive Ruby session in the browser. The console is automatically launched in case of an error or can be manually added to a view using <% console %>
. This functionality can be useful for debugging as the session is contextually bound (same variables) as the view it is displayed in.
5. Brakeman
The Brakeman gem can be a useful tool for checking known security vulnerabilities in a Ruby on Rails application. The checks it runs can include: SQL injection, XSS, DoS, RCE and many others. For a full list see here.