加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在开发中尝试exception_notification时的Actio

发布时间:2020-12-17 03:54:56 所属栏目:百科 来源:网络整理
导读:我想将exception_notification gem添加到我们的应用程序中,但是,当我尝试手动触发邮件时会发生这种情况: exception# = #ZeroDivisionError: divided by 0ExceptionNotifier::Notifier.exception_notification(request.env,exception)# = #ActionMailer::Bas
我想将exception_notification gem添加到我们的应用程序中,但是,当我尝试手动触发邮件时会发生这种情况:

exception
# => #<ZeroDivisionError: divided by 0>
ExceptionNotifier::Notifier.exception_notification(request.env,exception)
# => #<ActionMailer::Base::NullMail:0x007fa81bc7c610>
ExceptionNotifier::Notifier.background_exception_notification(exception)
# => #<ActionMailer::Base::NullMail:0x007fa81bf58190>

在上面的示例中,在某个控制器中有故意的1/0之后,控制台位于ApplicationController中的rescue_from Exception内的断点处.

我也在使用delayed_job,但是 – 毫不奇怪 – ExceptionNotifier :: Notifier.background_exception_notification(exception).deliver不会假脱机.

我已经在开发中设置了config.consider_all_requests_local = false,但仍然以exception_notification实例化NullMail.在应用程序的其他部分,邮件工作正常并使用sendmail.

我在这里做错了什么想法?谢谢你的帮助!

解决方法

您可能正在使用旧版本的ExceptionNotifier和更新版本的ActiveMailer :: Base.不在电子邮件功能中调用mail命令将导致返回ActionMailer :: Base :: NullMail实例而不是Mail实例.

从documentation开始:

class Notifier < ActionMailer::Base
  default :from => 'no-reply@example.com',:return_path => 'system@example.com'

  def welcome(recipient)
    @account = recipient
    mail(:to => recipient.email_address_with_name,:bcc => ["bcc@example.com","Order Watcher <watcher@example.com>"])
  end
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读