How to Stop the Rails Debugger for the Current Request

How to stop the Rails debugger for the current request

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

How do I quit from debugger without exiting my IRB session?

This SO question has a few good suggestions. It deals with specifically with debugging inside of loops. One great solution is to set the break point outside the loop, then from irb set it inside the loop and clear it manually when you want to.

Basically it comes down to putting a little bit of thought into where you set your breakpoints.

Other than that there doesn't appear to be anything else you can do.

Reasons rails is not stopping at debugger

This is a known issue in the debugger gem, see here (bullet point number three).

It seems that you are interested in why it doesn't work. The following is the explanation:

  • What debugger does is watching some events provided by ruby that tell the debugger when to stop. In this case, the debugger tracks what we call a line event that is triggered once per line executed, so in the case of the last line of a method, the debugger will stop in the next line event, which actually happens outside the method that is being debugged.

  • In byebug, however, I also track what we call return events, that are called every time a method finishes. That's why I'm able to stop execution before the method actually finishes.

Hope this helps.

considering I can start a debugging with --debugger, can I turn it off after I've started the console?

Since the --debugger option just requires the "debugger" gem, you could try to unload/unrequire the library. There are resources that will help you with this, just use Google. It will generally mean removing all of the constants defined by the library.

How can I inspect params and stop requisition in Rails 4?

you can use:

 return render text => article_params.to_yaml

Another option is use the debugger gem, which allows you a full inspect, but in the console, not in the browser.



Related Topics



Leave a reply



Submit