Ruby on rails 让超级异常通知程序工作
我已通过运行以下命令安装super_exception_notifier:Ruby on rails 让超级异常通知程序工作,ruby-on-rails,ruby,Ruby On Rails,Ruby,我已通过运行以下命令安装super_exception_notifier: sudo gem install super_exception_notifier 然后我尝试在我的项目中启用它,因为它可以发送邮件用于其他目的,比如这样。在environment.rb上,我添加了 # Notification configuration require 'exception_notifier' ExceptionNotifier.configure_exception_notifier do |co
sudo 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
在我的应用程序_controller.rb上,我有:
require 'exception_notifiable'
class ApplicationController < ActionController::Base
include ExceptionNotifiable
我错过什么了吗?因为无论我产生什么样的错误。无论是404,一个路由错误,在控制器或控制台中被零除,在开发或生产模式下,我都没有收到任何电子邮件和错误消息或任何东西
有什么想法吗?可能与此有关: 只有当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
巴勃罗
感谢您指出文档中的漏洞。我将设置一个空白的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
还有一件事,这个插件并没有废除rails标准,即公共场合的事情都是特朗普。因此,如果您公开了404.html,它将始终以404的形式呈现
彼得
嗯,我确实在生产过程中尝试过远程访问我的服务器;我希望控制台错误总是被发送,因为它们总是本地的。