【问题标题】:How to access ExceptionNotifier variables如何访问 ExceptionNotifier 变量
【发布时间】:2011-05-12 03:05:32
【问题描述】:

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

【问题讨论】:

  • 请说明你想在实践中做什么。有几种选择,具体取决于您要完成的任务。
  • @Simone:我想在 delay_job 工作人员中发生异常时发送异常通知。为了做到这一点,看来我必须编写自己的邮件程序,所以我想从 ExceptionNotifier 配置中获取 sender_addressexception_recipients

标签: ruby-on-rails-3 rack-middleware


【解决方案1】:

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

config.exception_subject_prefix = "[App Error] "
config.exception_sender = "support@example.com"
config.exception_recipients = %w{support@example.com}

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

配置变量可以在其他地方以Rails.configuration.exception_sender 等形式访问。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 2016-05-04
    • 2021-01-03
    • 2016-06-07
    • 2011-03-02
    • 1970-01-01
    相关资源
    最近更新 更多