在 Rails 中调试? [英] Debugging in Rails?

查看:28
本文介绍了在 Rails 中调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将如何在 RubyonRails 中相对"成功地调试?我知道并广泛使用以下内容:

  • 终端
  • Rails 控制台
  • 开发者工具
  • 日志文件(生产/开发)

如果有其他独立于运行环境的技术可用,这将有助于更快地调试.

解决方案

这些 gem 使调试 Rails 应用程序变得更加容易,无需使用真正的调试器:

group :development do宝石更好的错误"宝石binding_of_caller"宝石撬轨"结尾

更好的错误可在您遇到错误时使用 REPL 在浏览器中提供完整的堆栈跟踪.

使用 Pry,您可以在代码和下一个请求的某处放置一个 binding.pry 语句将停在那条线上.现在您可以在控制台中检查正在运行的代码,检查或更改变量并键入 exit 以恢复请求.

两个 gem 有很多共同点,对我来说主要区别在于 Better_errors 提供了很好的反馈和对不可预见错误的 REPL,而 pry 使我可以在需要时停止、检查和恢复请求.

How would you debug 'relatively' successfully in RubyonRails? I am aware and use extensively, the followings:

  • Terminal
  • Rails console
  • Developer Tools
  • Log Files (Production/Develpoment)

It would help to debug lot faster, if there are other techniques available independent to environment it is running on.

解决方案

These gems make debugging a Rails app a lot easier, without using a real debugger:

group :development do
  gem "better_errors"
  gem "binding_of_caller"
  gem "pry-rails"
end

Better errors gives you a full stack trace with REPL in your browser when you trip over an error.

With Pry you can put a binding.pry statement somewhere in your code and the next request will be halted at that line. Now you can inspect the running code in your console, inspect or change variables and type exit to resume the request.

Both gems have a lot in common, for me the main difference is that better_errors gives nice feedback and a REPL on unforeseen errors, while pry gives me the possibility to halt, inspect and resume a request when I want to.

这篇关于在 Rails 中调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆