加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何在rescue_from中呈现500页

发布时间:2020-12-17 03:59:57 所属栏目:百科 来源:网络整理
导读:我想在我的应用程序中出现异常时发送电子邮件并呈现常规500页.我找不到如何执行500页渲染: class ApplicationController ActionController::Base rescue_from StandardError do send_email_of_error # what goes here? end ...end 解决方法 再次提出异常可
我想在我的应用程序中出现异常时发送电子邮件并呈现常规500页.我找不到如何执行500页渲染:

class ApplicationController < ActionController::Base
  rescue_from StandardError do
     send_email_of_error
     # what goes here? 
  end

  ...
end

解决方法

再次提出异常可能是你想要的:

rescue_from StandardError do |exception|
  send_email_of_error
  raise exception
end

你也可以调用渲染来渲染自己的页面,the docs有一个例子.

但为什么重新发明轮子? exception notifier gem已经实现了这一点,并且可以进行定制和测试.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读