Debugging Rails Application
suggest changeDebugging matters when you need to follow an application’s logic and data. It helps you find logic bugs. Two common gems are debugger (Ruby 1.9.2 and 1.9.3) and byebug (Ruby 2.0 and later). On Ruby 2 and later, use byebug.
For debugging .rb files, follow these steps:
- Add
debuggerorbyebugto thedevelopmentgroup ofGemfile - Run
bundle install - Add
debuggerorbyebugas the breakpoint - Run the code or make request
- The Rails server stops at that breakpoint.
- The server terminal then works like
rails console. Inspect variables andparamsthere. - Type
nextand press Enter to run the next line. Typestepto enter a method call. Typefinishto run until the current method returns. - Type
c(continue) and press Enter to leave the breakpoint and resume the request.
In an .html.erb template, the breakpoint is <% byebug %> (or <% debugger %> with the old debugger gem).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents