Rails 上 Ruby 中的参数错误(参数数量错误)由于 Devise 和 PostageApp 的集成
Argument Error (wrong number of Arguments) in Ruby on Rails duing integration of Devise and PostageApp
我是一个相对较新的 RoR 爱好开发者。我使用 Devise 进行用户管理,并计划使用 PostageApp 发送 "forget password" 电子邮件。 RoR 版本为 4.2.0。
我已正确配置 PostageApp。并按照 PostageApp 网站上的说明进行操作。但是,我一直收到 "wrong number of arguments" 错误。
错误信息
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/devise/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/initializers/devise.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
reset_password_instructions(record, token, opts = {})
另外,看看 THIS post
当我们使用 devise 时,我们必须使用传递默认参数编写以下代码
app/models/user.rb
handle_asynchronously :send_reset_password_instructions
handle_asynchronously :send_confirmation_instructions
handle_asynchronously :send_on_create_confirmation_instructions
使用延迟作业活动记录发送包含排队过程的 Devise 电子邮件 gem
#创建新用户后发送确认邮件
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
我是一个相对较新的 RoR 爱好开发者。我使用 Devise 进行用户管理,并计划使用 PostageApp 发送 "forget password" 电子邮件。 RoR 版本为 4.2.0。
我已正确配置 PostageApp。并按照 PostageApp 网站上的说明进行操作。但是,我一直收到 "wrong number of arguments" 错误。
错误信息
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/devise/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/initializers/devise.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
reset_password_instructions(record, token, opts = {})
另外,看看 THIS post
当我们使用 devise 时,我们必须使用传递默认参数编写以下代码
app/models/user.rb
handle_asynchronously :send_reset_password_instructions
handle_asynchronously :send_confirmation_instructions
handle_asynchronously :send_on_create_confirmation_instructions
使用延迟作业活动记录发送包含排队过程的 Devise 电子邮件 gem
#创建新用户后发送确认邮件
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