我想在我的应用程序出现异常时发送电子邮件并呈现常规 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
您也可以致电render
呈现您自己的页面,the docs http://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html#method-i-rescue_from有一个这样做的例子。
但为什么要重新发明轮子呢?这异常通知器 gem https://github.com/smartinez87/exception_notification已经做到了这一点并且可以定制和测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)