[英]Lost values after switching email sending from AR_Mailer to DelayedJob
I've been using AR_Mailer for about 6 months without ever running into problems. 我一直在使用AR_Mailer大约6个月没有遇到问题。 I recently added DelayedJob for some administrative background jobs.
我最近为一些管理后台工作添加了DelayedJob。 Since DelayedJob also handles emails very well (thanks to DelayedMailer gem) I completely removed AR_Mailer from my application.
由于DelayedJob还可以很好地处理电子邮件(由于DelayedMailer gem),因此我从应用程序中完全删除了AR_Mailer。
Everything works perfectly except this email. 除了这封电子邮件,一切都很完美。 The password that is generated automatically is now lost.
现在自动生成的密码已丢失。
#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.
[....]
Any idea on why this bug occurs? 有没有想过为什么会出现这个错误? Thanks!
谢谢!
Configuration: Rails 2.3.2 & DelayedJob 2.0.4 配置:Rails 2.3.2和DelayedJob 2.0.4
I found out where the problem was. 我发现了问题所在。 I looked in the database at the entry created in the delayed_jobs table:
我在数据库中查找了delay_jobs表中创建的条目:
--- !ruby/struct:Delayed::PerformableMethod
object: LOAD;Notifier
method: :deliver_activation_instructions!
args:
- LOAD;User;589
The user
parameter is reloaded from the database by delayed_job before sending the email. 在发送电子邮件之前,delayed_job从数据库重新加载了
user
参数。 In that case, the password is lost because it's not stored in the database. 在这种情况下,密码将丢失,因为它没有存储在数据库中。
So I've updated the code in order to pass explicitly the password: 因此,我更新了代码以显式传递密码:
#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.
[....]
Hope this helps other too! 希望这对其他人也有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.