Debugging Rails Application

suggest change

Debugging 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:

  1. Add debugger or byebug to the development group of Gemfile
  2. Run bundle install
  3. Add debugger or byebug as the breakpoint
  4. Run the code or make request
  5. The Rails server stops at that breakpoint.
  6. The server terminal then works like rails console. Inspect variables and params there.
  7. Type next and press Enter to run the next line. Type step to enter a method call. Type finish to run until the current method returns.
  8. 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).

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents