Nowadays we have dynamic typed languages like Ruby that don’t even require semicolons! But that doesn’t mean we’re in the clear. We still have to debug. RoR has done a good job of building in a lot of debugging tools.
Here is my philosophy and methodology for debugging:
- Errors and Exceptions are the easiest: Load the web app, if there is an error or exception thrown in the webpage tackle that first. If I don’t know what the exception means e.g. InvalidAuthenticityToken, I will look it up. And read about it and usually that will lead me to a solution.
- I love logs! If the web app seems to load properly, but some functionality is broken I go look at the logs. You can add log statements based on the level of logging you want to controllers in RoR with the following code: logger.debug “BUGGY” or logger.info “YO”
- Data Corruption: to the Database! If the data appears to be displayed incorrectly then I go straight to the database.
- Look & Feel: if something is off with the way the page is rendered then it is most likely something I did wrong in HTML or CSS. I like using Firebug for CSS issues.
- Vijayashanker Code If something is off about the functionality, and I have a sense of where it is happening I will go through and read my code.
- Debugger Last: I’m not really a lazy person, but setting breakpoints and stepping through code can be tedious. So I save this as a last resort if I can’t use any of the above techniques to find my bug.
- I hate “debug” statements! I’m a neat freak, I don’t like polluting my code with debug statement, and creating more work for myself in having to go and remove them later. If I can’t get the debugger to do what I want then I will resort to using debug statements.
As I was debugging today I discovered a few good resources here are a few of them:
- Debugging Rails Applications (walks you through common debugging techniques and also explains logging levels and configurations)
- Logging Tips (Everything you ever wanted to know relating to logging in RoR)
- RoR Google Group (I found solutions and insights into most of the problems I was experiencing today)