Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从Rails中的错误处理程序中解救\u,使其无法捕获所有异常_Ruby On Rails_Exception Handling - Fatal编程技术网

Ruby on rails 从Rails中的错误处理程序中解救\u,使其无法捕获所有异常

Ruby on rails 从Rails中的错误处理程序中解救\u,使其无法捕获所有异常,ruby-on-rails,exception-handling,Ruby On Rails,Exception Handling,我的ApplicationController类中有自定义错误处理代码: unless ActionController::Base.config.consider_all_requests_local rescue_from Exception, :with => :render_error rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found rescue_from A

我的ApplicationController类中有自定义错误处理代码:

  unless ActionController::Base.config.consider_all_requests_local
    rescue_from Exception, :with => :render_error
    rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
    rescue_from ActionController::RoutingError, :with => :render_not_found
    rescue_from ActionController::UnknownController, :with => :render_not_found
  end
但是,如果我键入一个混搭且无效的URL,如:“/we/efe/qwe/wqeqw/qwe”,则带有
config.confidence\u all\u requests\u local=false的系统将为我提供标准Rails 404页面,而不是被以下内容捕获:

从ActionController::RoutingError中营救\u,:with=>:未找到渲染\u

查看异常跟踪日志,显示Rails正在引发一个
ActionController::RoutingError(没有与[GET]“/we/efe/qwe/wqeqw/qwe匹配的路由):
但是,我无法确定为什么我的处理程序没有捕捉到它


为什么这不起作用?

显然,这是Rails 3.2+引发ActionController::RoutingError异常的方式

答案是,您需要在路由的底部添加一个默认命名路由,以捕获所有未路由的请求:

get '*unmatched_route', :to => 'application#no_route'

请您发布
render\u not\u found
方法。并从公用文件夹中删除原来的404.html和500.html。这是开发环境还是测试环境还是生产环境?无需-显然这是Rails 3.2+引发ActionController::RoutingError的方式-答案是您需要在路由的底部添加一个默认命名路由(捕获所有未路由的请求:
get'*unmatched_route',:to=>“application#no_route”