- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
当我寻找问题时,例如针对特定的 ActiveRecord 对象,我经常发现自己在我的生产系统上执行以下操作:
# RAILS_ENV=production bundle exec
irb(main)> article = Article.find(123)
=> #<Article id: 123, title: "Foobar">
irb(main)> article.do_something(3)
NoMethodError: undefined method `id' for nil:NilClass
有时我无法重现,为什么 article.do_something(3)
行会抛出错误,所以我想直接在我的服务器上以生产模式进行调试。
现在的问题是:如何在对象/实例 article
上使用参数 3
进入方法 #do_something
?
当然,可以在该方法中设置一个断点,重新加载生产环境并让所有客户在该断点处等待,直到我完成调试...但这不是最好的主意。
So, is there a way to debug into a method of a specific instance from a running irb / pry session? (both would be ok)
最佳答案
在尝试和更多谷歌搜索之后,我想我找到了适合我的解决方案。
require 'byebug'
(或 require 'debugger'
对于旧的 ruby 版本)binding.pry; user.do_something
或 调试器; user.do_something
next
跳转到下一行(如果您启用了快捷方式,则只需使用 n
)以进入您的方法。这是我们生产系统中的一个完整示例:
[1] pry(main)> require 'byebug'
=> true
[2] pry(main)> user = User.find(2)
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
=> #<User id: 2, name="XXX XXX">
[3] pry(main)> user.full_name
NameError: undefined local variable or method address for #<User:0x0055b168663590>
[4] pry(main)> binding.pry; user.full_name
[68, 73] in /usr/src/app/app/models/user.rb
68: end
69:
70: def full_name
=> 71: "#{address.firstname} #{address.last_name}"
72: end
73: end
(byebug)
关于ruby-on-rails - 从生产 irb 调试方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36747003/
我正在尝试将文件加载到 IRB 中。我在桌面上保存了名为“Ruby.rb”的文件 如何将文件加载到 IRB? 我尝试过使用“加载“Ruby.rb”、“加载“Ruby””和“需要“Ruby.rb”。这些
当我们使用 Binding.irb 时,我该如何...使用 IRB 调试时跳到下一行? 或者每次我想暂停执行以进行调试时,我是否只放置大量的 binding.irb 行? 最佳答案 你不能。 IRB
当我们使用 Binding.irb 时,我该如何...使用 IRB 调试时跳到下一行? 或者每次我想暂停执行以进行调试时,我是否只放置大量的 binding.irb 行? 最佳答案 你不能。 IRB
我刚刚安装了 Ruboto-irb在我的 Android 设备上运行 Ruby IRB。 文档位于 https://github.com/ruboto/ruboto/wiki/Using-Ruboto
我今天刚刚安装了 rvm,它看起来非常方便/强大。 我想我已经掌握了窍门,但是...... 当使用安装了 rvm 的 ruby 并运行 irb 时,当我需要安装的 gem 时,比如“rvm”,我得
找了一圈,反正找不到用fzf在 irb 或 pry 控制台中搜索历史记录。有什么办法可以做到吗? 最佳答案 环顾四周后,我发现命令完成与 GNU Readline 相关联。 ,然后我发现了Readli
在我运行 irb 的每个目录中,我都有一个需要的 config/boot.rb 文件。如果这可以在我输入 irb 时自动加载,那就太好了,但我不确定如何从 .irbc 文件中引用我打开 irb 的目录
我知道这个命令是:需要文件名 但我猜这个命令是针对 ruby 1.9.4 而我使用的是 ruby 2.0.0 确切的消息是。 $require start.rb LoadError: can
当我运行 Rails 应用程序时,它会正确找到我安装的所有 gem。 这是我第一次尝试从 irb 内部调用一些 gem,但找不到它们。 blocke:~$ irb irb(main):001:0> r
我发现 IRB 作为试错式调试工具非常有用,我真的不知道问题出在哪里,但可以利用 IRB 的 REPL 特性快速迭代潜在列表重现问题并将其提炼出来的方法。 有时我决定重新打开属于已加载 gem 的类,
我在 ruby-doc 中找不到任何相关内容。 我可以在 IRB 中拥有这样的东西: 2.2.0 :012"> 或 2.2.0 :012?> 我不知道那些符号是什么意思。你知道 吗? 是警告我错过
我想知道如何着手创建在浏览器中运行的在线 IRB。我有一个想法,在我的博客中包含一个 irb 控制台,并为用户提供将我教程中的代码块直接发送到 irb 控制台的选项,以便他们可以使用它。 _为什么以前
我有这个脚本,它在执行时让用户进入 IRB session 。 很好,但是当我使用 *nix 管道获取输入时(例如使用 cat),IRB session 立即结束。 我可以将脚本(我们称之为 mysc
我正在运行带有 rbenv 的 Ruby 1.9.2。我最近将我的用户目录移动到另一个驱动器。 Ruby 和 irb 使用 which 出现。 $ which ruby /Volumes/Pig/Us
我正在摆弄各种小型硬件。试图学习它。我想运行 mruby。我已经为我的硬件编译了。并拥有框架以及包括 MIRB 和 MRUBY bins。 但我可能会喜欢我自己的 IRB 代码。我的职业是程序员,但自
当我在 irb 中输入以下行时,irb 终止。 $ irb irb(main):001:0> def !; end => :! irb(main):002:0> ! /usr/local/lib/ru
当我在 irb 中输入包含土耳其语字符的我的名字作为字符串输入时,irb 会打印到终端,就好像存在编码不匹配一样。但是,如果通过 puts 或 print 将字符串打印到控制台,则输出正是我所期望的。
Programming Ruby 1.9 & 2.0 一书中给出了以下示例: require 'irb' trap "INT" do IRB.start end count = 0 loop do
我正在与 IRB(实际上是 Wirble)一起练习。我想知道是否可以将 IRB 内部的任何黑客攻击转储到文件中以供以后比较、编辑和重用? 您可以随时创建类、方法和数据,并且交互式 session 会不
我刚刚更新了我的 ruby 版本,现在当我在命令行中运行 irb 时,我得到了这个奇怪的东西: 1.9.2p290 :001 > 每一行。之前是一个简单的> 我怎样才能把它取回来? 最佳答案 您可
我是一名优秀的程序员,十分优秀!