[英]Lost values after switching email sending from AR_Mailer to DelayedJob
我一直在使用AR_Mailer大約6個月沒有遇到問題。 我最近為一些管理后台工作添加了DelayedJob。 由於DelayedJob還可以很好地處理電子郵件(由於DelayedMailer gem),因此我從應用程序中完全刪除了AR_Mailer。
除了這封電子郵件,一切都很完美。 現在自動生成的密碼已丟失。
#app/models/notifier.rb
def activation_instructions(user)
from default_email
@bcc = BACK_UP
@subject = "Activation instructions"
recipients user.email
sent_on Time.now
body :root_url => root_url, :user => user
end
#app/views/notifier/activation_instructions.erb
Thanks for signing up.
Your password is <%=@user.password-%>. For security reasons please change this on your first connection.
[....]
有沒有想過為什么會出現這個錯誤? 謝謝!
配置:Rails 2.3.2和DelayedJob 2.0.4
我發現了問題所在。 我在數據庫中查找了delay_jobs表中創建的條目:
--- !ruby/struct:Delayed::PerformableMethod
object: LOAD;Notifier
method: :deliver_activation_instructions!
args:
- LOAD;User;589
在發送電子郵件之前,delayed_job從數據庫重新加載了user
參數。 在這種情況下,密碼將丟失,因為它沒有存儲在數據庫中。
因此,我更新了代碼以顯式傳遞密碼:
#app/models/notifier.rb
def activation_instructions(user, password)
from default_email
@bcc = BACK_UP
@subject = "Activation instructions"
recipients user.email
sent_on Time.now
body :root_url => root_url, :user => user, :password => password
end
#app/views/notifier/activation_instructions.erb
Thanks for signing up.
Your password is <%=@password-%>. For security reasons please change this on your first connection.
[....]
希望這對其他人也有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.