Придумайте асинхронное с помощью почтовой программы Mandrill неверное количество аргументов (1 для 2)

Я использую delayed_job для обработки фоновых заданий. Недавно я натолкнулся на гем devse_async, чтобы интегрировать delayed_job и разработать.

Я получаю неправильное количество аргументов (1 для 2), ошибка, когда delayed_job обрабатывает задание электронной почты в очереди. Должен отметить, что я использую API Mandrill для отправки этих писем.

отложенная работа консоли

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 ответ

Решение

Использование зашифрованных токенов базы данных было введено в devise 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
Другие вопросы по тегам