gpt4 book ai didi

ruby-on-rails - Rails 3.1 错误捕获

转载 作者:数据小太阳 更新时间:2023-10-29 06:45:13 25 4
gpt4 key购买 nike

我认为 Rails 3.1 正在改变引发错误的方式。任何人都可以协助或确认这一点吗?我正在尝试使用 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”,但我无法在任何地方确认这一点。

谢谢!

最佳答案

我假设以下代码出现在您的 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

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

unless config.consider_all_requests_local

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

unless ActionController::Base.consider_all_requests_local

或者这个(Rails 3 之后):

unless Rails.application.config.consider_all_requests_local

关于ruby-on-rails - Rails 3.1 错误捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6118626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com