1

バックグラウンドジョブを処理するために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
4

1 に答える 1

1

データベース暗号化トークンの使用は devise 3.1 ( https://github.com/plataformatec/devise/blob/master/CHANGELOG.md#310---2013-09-05 ) で導入されたため、confirmation_instructionsメーラー メソッドはそうではありません2 番目のパラメーターとして任意のトークンを期待します。

実際、メソッドのどこでもそのパラメーターを使用していないことに注意してくださいrecord.confirmation_token

メソッド シグネチャの 2 番目のパラメータを削除するだけで、準備完了です。

def confirmation_instructions(record)
  ...
end
于 2015-07-18T09:18:45.983 に答える