Mailer unable to access reset_token in User model

前端 未结 1 1544
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-21 17:46

faced with an issue where @user.reset_token returns nil.

app/views/user_mailer/password_reset.html.erb

<%= link_to \"Reset password\", edit_passwo         


        
相关标签:
1条回答
  • 2020-12-21 18:45

    You're not storing the reset_token in the database - you're storing the reset_digest.

    When you don't use workers, you're storing the reset_token in the User instance, then passing that same User instance to your mailer - hence the reset_token is still available.

    When you use workers, your worker only has the User's ID, so it's reloading the User instance from the database. Because the reset_token isn't being stored in the database, it's coming back nil.

    Either you should be saving the reset_token in the database, or your password email should be using reset_digest in the URL.

    0 讨论(0)
提交回复
热议问题