如何在rescue_from中渲染500页
我想在我的应用程序中出现exception时发送电子邮件并呈现常规500页。 我找不到如何执行500页面渲染:
class ApplicationController < ActionController::Base rescue_from StandardError do send_email_of_error # what goes here? end ... end
再次提出exception可能是你想要的:
rescue_from StandardError do |exception| send_email_of_error raise exception end
你也可以调用render
来渲染你自己的页面, 文档有一个例子。
但为什么重新发明轮子? exception通知程序gem已经执行此操作并且可以自定义和测试。
这种方法可能符合您的需求:
class ApplicationController < ActionController::Base rescue_from Exception, :with => :render_500 def render_500(exception) @exception = exception render :template => "shared/500.html", :status => 500 end end
可能,查看哨兵是有用的,是什么使系统中的一堆信息自动发出通知。
gem https://github.com/getsentry/raven-ruby
演示https://github.com/getsentry/sentry-demo