Yuval Karmi Yuval Karmi - 9 months ago 40
Ruby Question

How to stop the Rails debugger for the current request

Say I have a loop in my code that calls the rails debugger a few times

def show
animals = ['dog', 'cat', 'owl', 'tiger']
for animal in animals
# do something else

Assuming I started my server with the
option, when this page is viewed, the debugger is going to stop for every run of the loop.

I can type
every time it stops so the request continues, but that's tedious, especially if we're not talking about it showing up 4 times as in this example, but 400.
Is there a way to let the debugger continue without pausing at each point of the loop?

My currently workaround is restarting the server, but that's time consuming.

Answer Source

Just put conditions on the debugger statement so that it stops only when you want it to, e.g.:

debugger if animal == 'tiger'

or if, say, you want to examine the code only on loop 384:

animals.each_with_index do |animal, i|
  debugger if i == 384
  # do something

or put in a variable that will let you continue ad hoc:

continue_debugger = false
animals.each do |animal|
  debugger unless continue_debugger
  # in the debugger type `p continue_debugger = true` then `c` when done