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
put your debugger
statement somewhere before the iteration, then set a breakpoint inside the iteration which you can then clear later.
Example:
def index
debugger
@things = Thing.all
@things.each do |thing|
# ... something you want to check out in the debugger
thing.some_calculation
end
end
When you enter the debugger, set a breakpoint inside:
b app/controllers/things_controller.rb:42
(Where 42 is the line number you want to break at, like thing.some_calculation
above. Note that it has to be an executable line of code -- comments, blank lines won't work). The debugger will show a breakpoint number and location:
Breakpoint 1 at .../app/controllers/things_controller.rb:42
Now, every time you continue, you will stop at the breakpoint. When you're done and want to complete the request, delete the breakpoint:
delete 1
continue once more, and you will complete the request!