How to stop the Rails debugger for the current request

后端 未结 9 1398
既然无缘
既然无缘 2021-02-02 15:50

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
           


        
9条回答
  •  时光取名叫无心
    2021-02-02 16:20

    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
    end
    

    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
    end
    

提交回复
热议问题