开发者

Lost values after switching email sending from AR_Mailer to DelayedJob

开发者 https://www.devze.com 2023-02-07 18:40 出处:网络
I\'ve been using AR_Mailer for about 6 months without ever running into problems. I recently added DelayedJob for some administrative background jobs. Since DelayedJob also handles emails very well (t

I've been using AR_Mailer for about 6 months without ever running into problems. I recently added DelayedJob for some administrative background jobs. Since DelayedJob also handles emails very well (thanks to DelayedMailer gem) I completely removed AR_Mailer from my application.

Everything works perfectly except this email. The password that is generated automatically is now lost.

#app/models/notifier.rb 
def activation_instructi开发者_JS百科ons(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


I found out where the problem was. I looked in the database at the entry created in the delayed_jobs table:

  --- !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. 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!

0

精彩评论

暂无评论...
验证码 换一张
取 消