Troubleshooting Ruby on Rails
For our third project at Flatiron, we had to create a website using Ruby on Rails, and here is what I learned.
Byebug is your best friend. What is byebug? Byebug is a debugging gem that comes preinstalled with Rails. It can be placed anywhere in your code, from models to controllers to views. Let’s talk about how I used it.
I found byebug most helpful in the model and controllers for seeing what was being iterated through. This helped figure out what to check for. In the above example, I was able to troubleshoot for missing or blank fields that could have created problems for the user when creating a new order.
How do you setup controller methods that receive information from the views without knowing what they are? The answer is you can’t. Well, you can, but you’ll possibly run into some kind of error because you’re receiving something you know nothing about, or your blocking and important piece form getting in. In the controller, I used byebug to verify the params being sent into the methods so I could try to avoid any unwanted errors.
I found that byebug’s best feature is that you can use it in real-time with your app. This allows you to play around and see how you can work with the data coming in. It also helps you breakdown methods that you don’t understand how they work or why they won’t.
Another great tool for troubleshooting was adding a bang ‘!’ at the end of methods like save and create. By adding the bang you can get a better error message if something is going wrong.
These were my main ways of troubleshooting but as always StackOverflow, random videos on the internet and the Flatiron instructor videos are go tos as well. Happy Coding.