2015-11-16 42 views
2

我是一個相對新手的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 

謝謝!

回答

3

您只通過所需的參數之一reset_password_instructions時,它實際上需要3:

reset_password_instructions(record, token, opts = {}) 

此外,在THIS

+1

此外,使用'token'你獲取作爲參數,而不是'password_url'中的'record.reset_password_token'。 –

+0

good call @YogeshKhater;) – Cyzanfar

+0

謝謝Cyzanfar和Yogesh。非常有用的見解。 – equn

0

看看當我們使用的設計,我們有下面寫與通默認aruguments代碼

應用程序/模型/ user.rb

handle_asynchronously :send_reset_password_instructions 
    handle_asynchronously :send_confirmation_instructions 
    handle_asynchronously :send_on_create_confirmation_instructions 
與排隊過程3210

發送電子郵件設計使用延遲的工作活動記錄寶石

#Send確認郵件創建新的用戶

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

後#Send重置密碼電子郵件

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

#send解鎖電子郵件

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