ruby-on-rails – 如何阻止当前请求的Rails调试器
发布时间:2020-12-16 20:35:42 所属栏目:百科 来源:网络整理
导读:说我在我的代码中有一个循环,调用rails调试器几次 def show animals = ['dog','cat','owl','tiger'] for animal in animals debugger # do something elseend 假设我使用–debugger选项启动了我的服务器,当浏览此页面时,调试器将停止循环的每次运行. 我可以
说我在我的代码中有一个循环,调用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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |