使用 Mandrill 邮件程序设计异步错误数量的参数(1 为 2)

Devise async with Mandrill mailer wrong number of arguments (1 for 2)

我正在使用 delayed_job 来处理后台作业。我最近遇到了 devse_async gem 来集成 delayed_job 和设计。

当 delayed_job 处理队列中的电子邮件作业时,我收到错误数量的参数(1 对 2)错误。我应该注意到我正在使用 Mandrill 的 API 来发送这些电子邮件。

延迟作业控制台

Starting job worker
[Worker(host:MacBook-Pro.local pid:21007)] Job Devise::Async::Backend::DelayedJob#perform (id=1) RUNNING
[Worker(host:MacBook-Pro.local pid:21007)] Job Devise::Async::Backend::DelayedJob#perform (id=1) FAILED (0 prior attempts) with ArgumentError: wrong number of arguments (1 for 2)
[Worker(host:MacBook-Pro.local pid:21007)] 1 jobs processed at 30.3564 j/s, 1 failed

追踪

wrong number of arguments (1 for 2)
/Users/Sites/app/mailers/devise_mailer.rb:6:in `confirmation_instructions'

devise_mailer

class DeviseMailer < MandrillMailer::TemplateMailer
  include Devise::Controllers::UrlHelpers
  include Devise::Mailers::Helpers
  default from: 'no-reply@foobar.com'

  def confirmation_instructions(record, token)
    @resource = record

    # Route mailer to send the proper subject and template
    if @resource.pending_reconfirmation?
      confirmation_template = 'Reconfirmation Instructions'
      confirmation_subject = 'Confirm your new email'
    else
      confirmation_template = 'Confirmation Instructions'
      confirmation_subject = 'Confirmation Email'
    end

    # Include proper greeting in email based on User type
    recipient_name = nil
    if @resource.type == "Business"
      recipient_name = record.business_name
    else
      recipient_name = record.first_name
    end
    puts "sending confirmation email"
    host =   ActionMailer::Base.default_url_options[:host]
    mandrill_mail template: confirmation_template,
              subject:  confirmation_subject,
              from_name: 'foobar',
              to: { email: 'contact@foobar.ca' },
              vars: {
                'FNAME'                  => recipient_name,
                'LIST_COMPANY'           => "foobar",
                'HTML_LIST_ADDRESS_HTML' => "foobar",
                'CONFIRMATION_LINK'      => "%s/users/confirmation?confirmation_token=#{record.confirmation_token}" % ENV['MAIL_HOST']
                # "http://0.0.0.0:3000/users/confirmation?confirmation_token=#{record.confirmation_token}"
              },
              async: true   
  end
end

registrations_controller.rb

def new
  build_resource({})
  resource.build_supp_form
  respond_with self.resource
end

def create
  super
end

设计 3.1 (https://github.com/plataformatec/devise/blob/master/CHANGELOG.md#310---2013-09-05) 中引入了数据库加密令牌的使用,因此您的 confirmation_instructions 邮件程序方法不需要任何令牌作为第二个参数。

实际上您并没有在方法中的任何地方使用该参数,请注意您调用了 record.confirmation_token

只需删除方法签名中的第二个参数即可:

def confirmation_instructions(record)
  ...
end