When you're building applications with such a large open source community such as Ruby on Rails, it's important to know what resources you have at hand. RubyGems have thousands of contributors worldwide and is one of the biggest open source language communities around, why wouldn't you take advantage of that?
Here are some gems that I find myself using in every project:
A Ruby code standard enforcer and formatter, Rubocop is an essential gem for development, helping you write better code. We all know reading code is harder than writing it, so when you're given a community agreed set of code standards, why not use them?
Remember, writing code can be subjective, and if you're working in a team it's important you all agree on a style guide as it's there to help you.
Debugging can be a pain to say the least. When I was a junior dev, there were countless times where I'd be re-running code with a slightly different
puts every time until I could figure out what's wrong. Pry changed all that.
My most used feature of pry is by far
binding.pry. By placing a
binding.pry within your code, when it's ran your server will stop there and allow you to play around in the console.
Don't stop there though, as it says in the README: Pry is not just an alternative to IRB. Pry gives you access to so much more than just its local variables and methods. For example, you can navigate to completely different classes by just typing
cd MyClass or see all the different method calls on a class by
ls MyClass. If you've just used Pry for generic IRB commands, you've barely scratched the surface.
One of the best features of webpacker (in my opinion) is live reloading. Webpacker will generate a file,
bin/webpack-dev-server which when ran will keep an eye on your packs and when saved live reload for you.
Note: webpacker comes as a default gem with any project using Rails 6 and above. If you don't want to use webpacker you can simply run
rails new myapp --skip-webpack-install.
Whenever is a way of adding cron-jobs to your rails application. It might be sending out daily emails or checking and updating configurations, but whatever it is, whenever is always a gem I end up using somewhere along the line.
With minimal setup, Whenever will write the jobs for you and you can view them by simply running
No one likes to find out about bugs from the end-user. Whilst this can be unavoidable, exception notifications gives me a a head start fixing them.
When I use devise on projects that require authentication, the warden user key is stored in the session, allowing me to see who's produced the error. Users are impressed when you tell them you're fixing a bug they've encountered without them even raising it, talk about customer service!
Some close runners up include Devise, Audited and Fast JsonApi, but they are usually more situational.
This is obviously personal preference, so what gems do find yourself using every project?