The de-facto debugger for Rails is Byebug. It works with Rails were things like Pry fall short, comes recommended by the core Rails team, and is even bundled with Rails. This article will walk you through getting set up with basic Debugging Ruby on Rails With byebug.

The debugger permits the ability to understand what is going on inside a Ruby program while it executes and offers many of the traditional debugging features such as:



Setting up

Version 5.0 of Rails comes with Byebug, but if you don’t have it, you can simply add the following to your Gemfile and run bundle:

gem "byebug"

or you can also simply

gem install byebug

Alternatively, if you use bundler:

bundle add byebug --group "development, test"

You can enter byebug in a similar fashion to other debuggers: pick a point in the code at which to jump into the debugger and add:




for example,

If you were debugging Rails, you would add byebug to your code:

and run rails server

bin/rails s

Once the execution gets to your byebug command, you will receive a debugging prompt.

You can debug code from the command prompt now

Command-line options

Words of wisdom

The excellent pry-byebug adds nextstepfinishcontinue, and break commands to pry using byebug. Additionally, one of my default gems on any project in which I’m using minitest, is the fantastic minitest-byebug. This will kick you straight into a Byebug session in the event that one of your tests fails. With a little work, you can make this play nicely with Guard, to create a formidable unit testing tool. Finally, for you Sublime users, there is sublime_debugger, which wraps Byebug in a neat little GUI. Enjoy Debugging Ruby on Rails With byebug.

One Response