简体   繁体   English

Ruby on Rails运行时控制台

[英]Ruby on Rails Runtime Console

I am trying to find a way to get a rails console for a program during runtime with all instantiated variables. 我正在尝试找到一种在运行时获取所有实例化变量的程序的Rails控制台的方法。 The normal rails console does not have access to any instantiated variables of its respective running application. 普通的rails控制台无法访问其各自正在运行的应用程序的任何实例化变量。 For example, when a rails application crashes during runtime, a webpage will load with the error listed in red text, a snippet of the code where the error was raised, and a console at the bottom with access to variables instantiated during runtime. 例如,当Rails应用程序在运行时崩溃时,网页将加载以红色文本列出的错误,引发错误的代码段以及位于底部的控制台,可访问在运行时实例化的变量。

See image below for console im talking about 请参阅下图,了解控制台正在谈论的内容 在此处输入图片说明

The best thing I could find was a gem called pry, which seems to allow you to access a console during runtime by adding the line 'binding.pry' in your code at the point where you want access to the console. 我能找到的最好的东西是一个名为pry的gem,它似乎允许您在运行时通过在代码中要访问控制台的位置添加“ binding.pry”行来访问控制台。 I would be fine with this, but seeing as how rails already gives you access to this when your app crashes, I would think there is a "vanilla" way to do this. 我对此很好,但是当您的应用程序崩溃时,可以看到Rails已经为您提供了对此的访问权限,我认为这是一种“香草”的方式。 Unfortunately I can't find anything online about this feature in rails. 不幸的是,我在Rails中找不到关于此功能的在线信息。 This seems like such a valuable tool for debugging I can't see why rails doesn't implement this. 这似乎是一个非常有用的调试工具,我无法理解为什么Rails无法实现这一点。 Is there a better way to debug during runtime? 在运行时是否有更好的调试方法? a better gem? 更好的宝石?

I will suggest you to use Better Errors 我建议您使用更好的错误

Better Errors replaces the standard Rails error page with a much better and more useful error page. 更好的错误用更好,更有用的错误页面代替了标准的Rails错误页面。 It is also usable outside of Rails in any Rack app as Rack middleware. 它也可以在Rails之外的任何Rack应用中用作Rack中间件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM