与Mandrill邮件程序设计错误的参数数量(1为2)

时间:2015-07-14 23:51:43

标签: devise delayed-job mandrill devise-async

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

当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

1 个答案:

答案 0 :(得分:1)

在设计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