我使用Delayed Job作为我的ActiveJob
排队后端,并且我试图使用ActionMailer
的deliver_later
方法发送电子邮件。我相信我已经完成了Delayed Job的所有设置,并且在我的开发机器上运行了一个后台工作者。ActionMailer无法找到reset_token,报告缺失:id密钥
当我发送密码重置电子邮件,我收到以下错误:
[Worker(host:Computer pid:7240)] Job ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper (id=1) FAILED (5 prior attempts) with ActionView::Template::Error: No route matches {:action=>"edit", :controller=>"password_resets", :email=>"[email protected]", :id=> nil} missing required keys: [:id]
这里是我如何发出的密码重置邮件。这个位于我User
模型:
def send_password_reset_email
UserMailer.password_reset(self).deliver_later
end
我的密码重置设置非常相似,在该this SO post一个我不存储我的数据库reset_token
,而是把它作为一个虚拟的属性,我认为这可能是我的问题,但我想尽可能避免存储该值。有没有办法将生成的reset_token
传递给Delayed Job worker?我的问题也可能与其他问题有关。
任何帮助将不胜感激!
感谢您分享您的解决方案。在我写下我的解决方案后不久,我走了一条类似于此的路线。我创建了一个单独的作业,并将密码重置令牌传递到作业有效内容中,如下所示:此代码在'User'模型中调用。 'SendPasswordResetJob.perform_later(self.id,self.password_reset_token)' – Alexander