How to stop the Rails debugger for the current request

后端 未结 9 1361
既然无缘
既然无缘 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:33

    I have another answer to this one: set a @debug on the class that you want to debug. That way you can do:

      if (@debug && (the_condition)) then debugger end
    

    or

      debugger unless !@debug 
    

    then when you are done with the debugger just @debug = false and c.

    However, I'm not really happy with having debugger 'hard stops' in live code. These are the kind of things that can be accidentally checked in and forgotten about until something breaks. The @debug would certainly fall under that as well. To that end I think my ideal solution would use Matt's idea and a script that sets up a breakpoint inside the object when the object is created. That way you'd have the debugging that you want but you wouldn't have any code in source control that is specifically for development. I'll update this answer if I find such a solution.

提交回复
热议问题