config.exceptions_app 在 rails 中不起作用

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

Rag*_*war 6

好吧,事实证明该变量config.consider_all_requests_local设置为 true,因此我的请求没有被路由到自定义错误页面。