输入无效命令时rails控制台中的额外行项目是什么?

时间:2015-03-26 11:24:59

标签: ruby-on-rails gem rails-console

具体来说,我明白了:

Loading development environment (Rails 4.2.1)
irb(main):001:0> f
NameError: undefined local variable or method `f' for main:Object
from (irb):1
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in `start'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in `start'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
from /Users/benjamin/demo/bin/rails:8:in `<top (required)>'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/commands/rails.rb:6:in `call'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/command_wrapper.rb:38:in `call'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:183:in `block in serve'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:156:in `fork'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:156:in `serve'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:131:in `block in run'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:125:in `loop'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application.rb:125:in `run'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/spring-1.3.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/benjamin/.rbenv/versions/2.2.1/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

如何永久隐藏这些内容,只看到实际的错误消息?我在网上发现了一些显示如何暂时隐藏这些订单项的内容,包括:

IRB.CurrentContext.back_trace_limit = 0

但是没有永久性的。

感谢帮助!

1 个答案:

答案 0 :(得分:0)

额外的行是“回溯”,因为您已从当前的上下文调用中正确识别。

我认为您需要按照here所述添加.irbrc文件。这通常位于您的主目录中,但如果主目录不包含,则它将使用当前目录中的.irbrc文件。

在该文件中,每次拨打irbrails console时,您都可以添加一行来限制回溯的大小:

IRB.conf[:BACK_TRACE_LIMIT] = 0

您可能不希望将其减少到零,因为如果错误消息本身不是特别有用,它有时会提供有关错误可能来源的线索。