Rails:关闭错误显示

Pau*_* S. 4 ruby ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2

当我通过URL访问我的Rails项目中不存在的帖子时,/posts/13浏览器会显示详细错误:

ActiveRecord::RecordNotFound in PostsController#show

Couldn't find Post with ID=13
Rails.root: ...
...
Request

Parameters:

{"id"=>"13"}
...
Run Code Online (Sandbox Code Playgroud)

有没有办法关闭这个详细的错误显示?

shi*_*ime 10

试试这个:

  • 在生产中运行服务器 $ rails s -e production

  • 删除ActionDispatch :: DebugExceptions中间件

    config.middleware.delete(ActionDispatch::DebugExceptions)

  • config.consider_all_requests_local = false在您的环境配置中设置