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.
Installation of the gem is simple enough, according the gem’s documentation:
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!
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.