Rails在不同的环境下,对错误的处理是不一样的,在开发和测试环境中提供开发级别的错误,在生产环境中提供Application Error的错误。
1、设置全局的异常处理程序,在application.rb中增加:
代码 def rescue_action_in_public(exception) logger.error("rescue_action_in_public executed") case exception when ActiveRecord::RecordNotFound, ::ActionController::RoutingError, ::ActionController::UnknownAction logger.error("404 displayed") render(:file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found") else logger.error("500 displayed") render(:file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error") # SystemNotifier.deliver_exception_notification(self, request, # exception) end end 才能显示错误页面 |