集成Devise和PostageApp时RubyonRails中的Argument Error(错误的Arguments



我是一个相对新手的RoR爱好开发人员。我使用Devise进行用户管理,并计划使用PostageApp发送"忘记密码"电子邮件。RoR版本为4.2.0。

我已正确配置PostageApp。并按照PostageApp网站上的说明进行操作。然而,我总是得到一个"错误的论点数量"的错误。

错误消息

2015-11-16T15:01:07.785094+00:00 app[web.1]: MyDeviseMailer#reset_password_instructions: processed outbound mail in 0.8ms
2015-11-16T15:01:07.785091+00:00 app[web.1]: 
2015-11-16T15:01:07.785415+00:00 app[web.1]: Completed 500 Internal Server Error in 597ms
2015-11-16T15:01:07.775613+00:00 app[web.1]:    (0.5ms)  BEGIN
2015-11-16T15:01:07.781596+00:00 app[web.1]:    (1.6ms)  COMMIT
2015-11-16T15:01:07.787783+00:00 app[web.1]: 
2015-11-16T15:01:07.787786+00:00 app[web.1]: ArgumentError (wrong number of arguments (3 for 1)):
2015-11-16T15:01:07.787787+00:00 app[web.1]:   app/mailers/devise/mailer.rb:13:in `reset_password_instructions'

app/mailers/devert/mailer.rb

class MyDeviseMailer < PostageApp::Mailer
include Devise::Mailers::Helpers
def confirmation_instructions(record)
# PostageApp specific elements (example):
postageapp_template 'my-signup-confirmation'
postageapp_variables :email => record.email,
:link  => confirmation_url(:confirmation_token => record.confirmation_token)
devise_mail(record, :confirmation_instructions)
end
def reset_password_instructions(record)
# PostageApp specific elements (example):
postageapp_template 'my-password-reset'
postageapp_variables :name => record.name ||= record.email,
:link => password_url(:reset_password_token => record.reset_password_token)
devise_mail(record, :reset_password_instructions)
end
def unlock_instructions(record)
# PostageApp specific elements (example):
postageapp_template 'my-unlock-instructions'
postageapp_variables :name => record.name ||= record.email,
:link => unlock_url(:unlock_token => record.unlock_token)
devise_mail(record, :unlock_instructions)
end
protected
# Ensures template subject is used instead of the default devise mailer subject.
def headers_for(action)
headers = super
headers[:subject] = ‘’
headers
end
end

config/ininitializers/devert.rb

Devise.setup do |config|
config.mailer = "MyDeviseMailer"
config.mailer_sender = '"Webmaster" <no-reply@mysite.com>'
require 'devise/orm/active_record'
config.case_insensitive_keys = [ :email ]
config.strip_whitespace_keys = [ :email ]
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.reconfirmable = true
config.expire_all_remember_me_on_sign_out = true
config.password_length = 8..128
config.reset_password_within = 6.hours
config.sign_out_via = :delete
end

谢谢!

reset_password_instructions实际需要3:时,您只将一个必需的参数传递给它

reset_password_instructions(record, token, opts = {})

此外,还可以查看THIS post

当我们使用设备时,我们必须编写以下代码,并通过默认的aruguments

app/models/user.rb

  handle_asynchronously :send_reset_password_instructions
  handle_asynchronously :send_confirmation_instructions
  handle_asynchronously :send_on_create_confirmation_instructions 

使用延迟作业活动记录宝石发送带有排队过程的Devise电子邮件

#创建新用户后发送确认电子邮件

def send_on_create_confirmation_instructions
    Devise::Mailer.delay.confirmation_instructions(self, :confirmation_instructions, opts={})
  end

#发送重置密码电子邮件

def send_reset_password_instructions
    Devise::Mailer.delay.reset_password_instructions(self, :reset_password_instructions, opts={})
  end

#发送解锁电子邮件

def send_unlock_instructions
    Devise::Mailer.delay.unlock_instructions(self, :unlock_instructions, opts={})
  end

相关内容

最新更新