我是一個相對新手的RoR業餘愛好開發人員。我使用Devise進行用戶管理,並計劃使用PostageApp發送「忘記密碼」電子郵件。 RoR版本是4.2.0。Devise和PostageApp集成在Ruby on Rails中的參數錯誤(錯誤數量的參數)
我已經正確配置了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'
應用程序/郵寄者/設計/ 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
配置/初始化/ devise.rb
Devise.setup do |config|
config.mailer = "MyDeviseMailer"
config.mailer_sender = '"Webmaster" <[email protected]>'
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
謝謝!
此外,使用'token'你獲取作爲參數,而不是'password_url'中的'record.reset_password_token'。 –
good call @YogeshKhater;) – Cyzanfar
謝謝Cyzanfar和Yogesh。非常有用的見解。 – equn