如何在Ruby on Rails中禁用详细的控制台?

时间:2014-05-10 22:03:32

标签: ruby-on-rails-4

当我使用控制台进行RoR并且出现错误时,我会获得所使用的gems / lib列表,例如

SyntaxError: /Users/user/Sites/Jobsite/app/models/subject.rb:11: syntax error, unexpected ']', expecting ')'
    where(["name LIKE ?"], "%#{query}%"])
                                        ^
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `load'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `block in load_file'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:633:in `new_constants_in'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:442:in `load_file'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:342:in `require_or_load'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:480:in `load_missing_constant'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:180:in `const_missing'
    from (irb):1
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.1.0/lib/rails/commands/console.rb:90:in `start'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.1.0/lib/rails/commands/console.rb:9:in `start'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
    from /Users/user/Sites/Jobsite/bin/rails:8:in `<top (required)>'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/user/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /Users/user/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/user/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

我真的需要这个吗?或者我可以以某种方式禁用它,因为每次我得到它,我需要向上滚动,我不会那么容易看到错误信息本身。

2 个答案:

答案 0 :(得分:0)

您可以尝试更改log level

您还可以通过将其置于初始化程序中来关闭SQL日志记录:

ActiveRecord::Base.logger = nil

也许像 - config/initializers/activerecord_logger.rb

此处有更多信息 - Disable Rails SQL logging in console

答案 1 :(得分:0)

您可以在consider_all_requests_local中将设置truefalse更改为config/environments/development.rb,这样就不会显示堆栈跟踪:< / p>

Jobsite::Application.configure do
  config.consider_all_requests_local = false
end