Rag*_*war 5 ruby error-handling ruby-on-rails
我正在尝试为所有 404 和 500 错误呈现自定义错误页面。所以我在 ErrorController 类中定义了两个方法 not_found 和 internal_server_error 。
class ErrorController < ApplicationController
def not_found
#method which renders custom error page
render_error()
end
def internal_error
#method which renders custom error page
render_error()
end
end
Run Code Online (Sandbox Code Playgroud)
在我的 config/routes.rb 我已经包括
get '/404', to: 'error#not_found'
get '/500', to: 'error#internal_error'
Run Code Online (Sandbox Code Playgroud)
在 config/application.rb 中,我已经将 config.exceptions_app 初始化为
config.exceptions_app = self.routes
Run Code Online (Sandbox Code Playgroud)
但是当我输入 URL 为http://localhost:3000/404 时,我仍然得到 rails 提供的默认页面,而不是我的自定义错误页面。
关于我做错了什么的任何线索都会有所帮助。
更新:
我正在使用 ruby 2.3.4 和 rails 5.0.5
| 归档时间: |
|
| 查看次数: |
2387 次 |
| 最近记录: |