假设我的代码中有一个循环调用了 rails 调试器几次
def show
animals = ['dog', 'cat', 'owl', 'tiger']
for animal in animals
debugger
# do something else
end
假设我使用 --debugger
选项启动我的服务器,当查看此页面时,调试器将在每次循环运行时停止。
每次它停止时我都可以键入 cont
以便请求继续,但这很乏味,尤其是如果我们不是像本例那样谈论它出现 4 次,而是 400 次。
有没有办法让调试器在循环的每个点都不停顿地继续?
我目前的解决方法是重新启动服务器,但这很耗时。
最佳答案
只需在调试器语句上设置条件,以便它仅在您需要时停止,例如:
debugger if animal == 'tiger'
或者,如果您只想检查循环 384 上的代码:
animals.each_with_index do |animal, i|
debugger if i == 384
# do something
end
或者放入一个变量,让您可以临时继续:
continue_debugger = false
animals.each do |animal|
debugger unless continue_debugger
# in the debugger type `p continue_debugger = true` then `c` when done
end
关于ruby-on-rails - 如何停止当前请求的 Rails 调试器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6185668/