Rails 3.1 错误捕获 [英] Rails 3.1 Error Catching

查看:46
本文介绍了Rails 3.1 错误捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为 Rails 3.1 正在改变引发错误的方式.任何人都可以协助或确认这一点吗?我正在尝试使用 Rails 3.1.0.rc1 创建自定义错误页面

I think Rails 3.1 is changing the way that errors are raised. Can anyone assist or confirm this? I'm attempting to create custom errors pages with Rails 3.1.0.rc1

unless 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
    rescue_from ActionController::UnknownAction, :with => :render_not_found
end

^^ 这不起作用.

config.consider_all_requests_local       = true

默认情况下,这是在我的开发环境中.我假设 Rails 3.1 删除了action_controller",但我无法在任何地方确认这一点.

That is in my development environment by default. I'm assuming Rails 3.1 removes the "action_controller" but I can't confirm this anywhere.

谢谢!

推荐答案

我假设以下代码出现在您的 ApplicationController 中?

I'm assuming the following code appears in your ApplicationController?

unless 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
  rescue_from ActionController::UnknownAction, :with => :render_not_found
end

如果是这样,请尝试替换此行:

If so, try replacing this line:

unless config.consider_all_requests_local

使用这一行(我认为是 Rails 3 之前的版本):

with this line (pre Rails 3 I think):

unless ActionController::Base.consider_all_requests_local

或者这个(发布 Rails 3):

or this (post Rails 3):

unless Rails.application.config.consider_all_requests_local

这篇关于Rails 3.1 错误捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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