我通过运行:
安装了super_exception_notifiersudo gem install super_exception_notifier
然后我尝试在我的项目中启用它(已经有邮件工作,因为它发送电子邮件用于其他目的),就像这样。在environment.rb上我添加了
# Notification configuration
require 'exception_notifier'
ExceptionNotifier.configure_exception_notifier do |config|
config[:exception_recipients] = %w(info@isitsciencefiction.com)
config[:notify_error_codes] = %W( 404 405 500 503 )
end
在我的application_controller.rb上我有:
require 'exception_notifiable'
class ApplicationController < ActionController::Base
include ExceptionNotifiable
我错过了什么吗?因为无论我生成什么错误。在开发或生产模式下,404,路由错误,在控制器或控制台中除以零,我都没有收到任何电子邮件,也没有任何错误消息或任何内容。
有什么想法吗?
答案 0 :(得分:0)
也许它与此有关: http://github.com/pboling/exception_notification
只有在确定IP地址不是本地IP地址时才会发生电子邮件通知。您可以指定某些地址始终为本地地址,以便您获得详细错误而不是通用错误页面。您可以在控制器(甚至是每个控制器)中执行此操作。
consider_local "64.72.18.143", "14.17.21.25"
您也可以指定子网掩码,以便将所有匹配的地址视为本地:
consider_local "64.72.18.143/24"
地址“127.0.0.1”始终被视为本地地址。如果要完全重置所有地址列表(例如,如果您希望“127.0.0.1”不被视为本地地址),您可以在控制器中的某个地方执行此操作:
local_addresses.clear
答案 1 :(得分:0)
巴勃罗,
感谢您指出文档中的漏洞。我将设置一个空白的rails项目,然后清楚地列举这些步骤。我已经更新了自述文件以响应您在github上创建的票证。
为了帮助解决您的问题,这就是我设置它的方式,(它对我有用!:) 并非所有部分都对它的工作至关重要,但我不是在编辑它(很多),所以你可以看到我所拥有的:
我的环境中有这个.rb:
config.load_paths += %W( #{RAILS_ROOT}/app/middlewares #{RAILS_ROOT}/app/mixins #{RAILS_ROOT}/app/classes #{RAILS_ROOT}/app/mailers #{RAILS_ROOT}/app/observers )
我在config / initializers / super_exception_notification.rb
中有一个初始化程序 #The constants ($) are set in the config/environments files.
ExceptionNotifier.configure_exception_notifier do |config|
config[:render_only] = false
config[:skip_local_notification] = false
config[:view_path] = 'app/views/errors'
config[:exception_recipients] = $ERROR_MAIL_RECIPIENTS
config[:send_email_error_codes] = $ERROR_STATUS_SEND_EMAIL
#config[:sender_address] = %("RINO #{(defined?(Rails) ? Rails.env : RAILS_ENV).humanize} Error" )
config[:sender_address] = "errors@swankywebdesign.com"
config[:email_prefix] = "[RINO #{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} ERROR] "
end
然后在我的application.rb中我有这个:
include ExceptionNotifiable, CustomEnvironments
alias :rescue_action_locally :rescue_action_in_public if Environments.local_environments.include?(Rails.env)
self.error_layout = 'errors'
self.exception_notifiable_verbose = false
self.exception_notifiable_silent_exceptions = [MethodDisabled]
然后我在app / mixins目录中也有这个mixin:
module CustomEnvironments
module Environments
def self.local_environments
%w( development test )
end
def self.deployed_environments
%w( production staging )
end
end
end
另外一件事,这个插件并没有废除轨道标准,即公开的东西是特朗普。因此,如果您在公共场合使用404.html,它将始终以404的形式呈现。