2011-05-12 135 views
2

如何在我的自定义邮件程序类中访问ExceptionNotifier变量,例如sender_addressexception_recipients?由于ExceptionNotifier是作为Rack中间件实现的,所以我不知道该如何去做。如何访问ExceptionNotifier变量

+0

请解释你想在实践中做什么。有几种选择,取决于你想要完成什么。 – 2011-05-12 08:59:54

+0

@Simone:我想在delayed_job worker发生异常时发送异常通知。为了做到这一点,它看起来像我必须编写我自己的邮件程序,所以我想从ExceptionNotifier配置中获得'sender_address'和'exception_recipients'。 – 2011-05-12 09:21:22

回答

1

我仍然不知道如何访问ExceptionNotifier变量,所以我决定在解决方法是添加这些变量到Rails的配置代替,并用它们来同时配置ExceptionNotifier和我的自定义邮件:

config.exception_subject_prefix = "[App Error] " 
config.exception_sender = "[email protected]" 
config.exception_recipients = %w{[email protected]} 

config.middleware.use "::ExceptionNotifier", 
         :email_prefix => config.exception_subject_prefix, 
         :sender_address => %{ #{config.exception_sender} }, 
         :exception_recipients => config.exception_recipients 

配置变量可以作为Rails.configuration.exception_sender等访问其他地方。