每天一剂Rails良药之Getting Notified of Unhandled Exceptions中也提到了Exception Notification插件
该插件在production环境下,当程序出错时会给recipient发送notification邮件
Exception notification只会在访问的IP地址不为local时才工作,我们可以配置认为是local的IP:
consider_local "64.72.18.143", "14.17.21.25"
consider_local "64.72.18.143/24"
如果我们要清除本地地址列表,比如想让"127.0.0.1"不被认为是local的,我们可以在controller里加上:
local_addresses.clear
在views/exception_notifier目录下的视图文件可以访问如下变量:
* @controller: the controller that caused the error
* @request: the current request object
* @exception: the exception that was raised
* @host: the name of the host that made the request
* @backtrace: a sanitized version of the exception's backtrace
* @rails_root: a sanitized version of RAILS_ROOT
* @data: a hash of optional data values that were passed to the notifier
* @sections: the array of sections to include in the email
通过修改ExceptionNotifier.sections变量,我们可以添加和排除一些视图
添加视图时,我们只需把新的视图的名字加到ExceptionNotifier.sections列表并定义相应的partial即可
如果新定义的partial需要自定义的变量信息,我们可以使用exception_data宏:
class ApplicationController < ActionController::Base
...
protected
exception_data :additional_data
def additional_data
{ :document => @document,
:person => @person }
end
...
end
默认下email notifier只会对critical errors进行notify
对于ActiveRecord::RecordNotFound和ActionController::UnknownAction只会render你的public/404.html文件
其他异常则会render你的public/500.html并发送email notification
具体规则参考exception_notification的源文件即可
如果你想更改发送email notification的规则,只需实现或修改rescue_action_in_public方法即可
分享到:
相关推荐
ExceptionNotification :: Shoryuken 这个Ruby宝石是宝石的扩展,并提供了一组通知器,用于在 worker中发生错误时发送通知。 如果将Shoryuken worker用作异步进程,这将很有用。 安装 将此行添加到您的应用程序的...
复杂Rails系统架构优化
中文世界唯一一本Rails 4.0.0 + Ruby 2.0.0 的自學書籍
RestFul_Rails_Dev_v_0.1 RestFul_Rails_Dev_v_0.1
InspiniaAdmin 2.6.1 Rails_Full_Version
activity_notification使用 , 和 ORM支持Rails 5.0+。 已针对 , ,带有ActiveRecord的 ,带有Mongoid的和带有Dynamoid的进行了测试。 如果您使用的是Rails 4.2,请使用或版本的activity_notification 。 关于 ...
rails_apps_composer, 一个 gem,为 Rails 启动应用程序创建 Rails 应用程序模板 Rails 应用编辑器 Rails 应用程序编辑器 gem 安装一个 命令行 工具来从"食谱"的Collection 组装 Rails 应用程序。"你可以使用 rails_...
介绍插件,用于对记录进行排序(使用 gem)安装要启用rails_admin_acts_as_list,请将以下内容添加到您的Gemfile : gem 'rails_admin_acts_as_list'gem 'rails_admin' 重要提示: rails_admin_acts_as_list之前必须...
Api-rails5_api_tutorial.zip,了解如何在michael hartl的rails 5教程上构建一个现代api立即在rails应用程序中构建一个api!(Rails 5版本),一个api可以被认为是多个软件设备之间通信的指导手册。例如,api可用于web...
agile_web_development_with_rails_3rd_edition.9994652073.pdf
rails_semantic_logger, Rails 语义记录器用语义记录器替换 Rails 缺省记录器 Rails 语义记录器 语义记录器用语义记录器替代 Rails 缺省记录器。http://github.com/rocketjob/rails_semantic_logger文档有关完整文档...
Rails_Recipes_with_Source_Code
inspinia admin 2.5 中的 Rails_Full_Version
Rails_3_Cheat_Sheets.pdf
NULL 博文链接:https://zyn-zyn.iteye.com/blog/1163148
rails_best_practices rails_best_practices是用于检查Rails代码质量的代码度量工具。 它支持以下ORM / ODM: 活动记录 蒙古型 mongomapper 以及以下模板引擎: erb 哈姆 减肥 拉布尔 rails_best_practices...
应用Rails进行REST 开发 ,翻译自《RESTful Rails Development》
ruby_on_rails_3_入门教程(中文)
您可以将此异常处理程序挂接到所有Rails应用程序中,并将异常报告收集到一个位置。 异常处理程序仅包含后端,您必须创建自己的前端才能查看和管理错误报告。 Rails Engine的管理界面是界面的简单添加,或用作构建您...
gem 'rails_admin_image_manager' 跑步 $ bundle install 安装RailsAdmin_ImageManager $ rails generate rails_admin_image_manager:install 将上传文件路径添加到您的.gitignore文件中 /public/rails_admin_...