Rails:关闭错误显示

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

 ActiveRecord::RecordNotFound in PostsController#show Couldn't find Post with ID=13 Rails.root: ... ... Request Parameters: {"id"=>"13"} ... 

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

试试这个:

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

  • 删除ActionDispatch :: DebugExceptions中间件

    config.middleware.delete(ActionDispatch::DebugExceptions)

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