My favorite part of Rails (so far), the web-console gem

Image for post
Image for post

I really enjoyed getting to learn Ruby on Rails. When I was first learning Ruby, it was a little difficult for me to visualize what exactly was happening, and Rails made it easier by letting me spin up the Rails server and see my changes in real-time.

But what about debugging? When I was first learning Ruby I was introduced to the Pry gem, that let me pause my code in whatever method I was working on, and I was wondering if there was something similar for Rails. The answer was ‘Yes, several’, but my favorite became the web-console gem.

Image for post
Image for post
This little black window at the bottom of the screen is my friend.

Installation of the gem is simple enough, according the gem’s documentation:

Image for post
Image for post

And that’s it, you now have access to a full console in your web browser. You can access the console manually, by adding <% console %> to a view page and the console will appear when that view is accessed. My favorite way though, is that the console launches automatically in case of an error!

Image for post
Image for post

Once it hits an error you get your error message and the console automatically to start debugging your error. This console allows you to execute Ruby commands based on the page that you are working on. I found it super useful for testing my variables and double checking my outputs, without having to go back to my code to insert a byebug, a binding.pry, or other debugging tool! It may only save a few minutes, but if you’re like me and you hit a lot of errors those minutes add up.

Computer Support Tech turned Software Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store