Rails 3.1 错误捕获

编程入门 行业动态 更新时间:2024-10-28 08:22:08
本文介绍了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 错误捕获

本文发布于:2023-10-11 04:31:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1480692.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!