Debugging Rails

Install pry, pry-byebug, and pry-rails gems.
To add a breakpoint, type binding.pry wherever you want your breakpoint to happen.
In console use coninue, step, next, finish commands:

step: Step execution into the next line or method. Takes an optional numeric argument to step multiple times.

next: Step over to the next line within the same frame. Also takes an optional numeric argument to step multiple lines.

finish: Execute until current stack frame returns.

continue: Continue program execution and end the Pry session.

To add shortcuts to ^ commands, add to ~/.pryrc:
Pry.commands.alias_command ‘c’, ‘continue’ rescue nil
Pry.commands.alias_command ‘s’, ‘step’ rescue nil
Pry.commands.alias_command ‘n’, ‘next’ rescue nil
Pry.commands.alias_command ‘f’, ‘finish’ rescue nil

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.