config.exceptions_app在Rails中不起作用 [英] config.exceptions_app not working in rails

查看:70
本文介绍了config.exceptions_app在Rails中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为所有404和500个错误呈现一个自定义错误页面。因此,我在ErrorController类中定义了两个方法not_found和internal_server_error。

I'm trying to render a custom error page for all 404 and 500 errors. So I have defined two methods not_found and internal_server_error in ErrorController class.

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

并且在我的config / routes.rb中,我已经包括了

and in my config/routes.rb I've included

get '/404', to: 'error#not_found'

get '/500', to: 'error#internal_error'

在config / application.rb中,我已将config.exceptions_app初始化为

and in config/application.rb I've initialized config.exceptions_app as

config.exceptions_app = self.routes

但是当我输入 http:// localhost:3000/404 ,我仍在获得Rails提供的默认页面,而不是我的自定义错误页面。

But when I enter URL as http://localhost:3000/404 , I'm still getting the default page provided by rails and not my custom error page.

任何关于我做错事情的线索都会有所帮助。

Any clue about what I'm doing wrong would be helpful.

更新:

我正在使用ruby 2.3.4和rails 5.0。 5

I'm using ruby 2.3.4 and rails 5.0.5

推荐答案

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

Well it turns out that the variable config.consider_all_requests_local was set to true and hence my requests weren't being routed to custom error pages.

这篇关于config.exceptions_app在Rails中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆