Reputation: 29094
In my Rails
application, I have a form for admin to create normal users. In create
action
, I am generating a reset password token, and sending a welcome mail to the user, with a link in it to reset his password. This is my code.
@user = User.new params[:user]
@user.reset_password_token = User.reset_password_token
@user.reset_password_sent_at = Time.now.utc
if @user.save
UserMailer.welcome_email(@user).deliver
..
This works fine, but I have another app with the same code, but uses devise 3.2.2
in which I get the this error.
NoMethodError - undefined method `reset_password_token' for User:Class:
I see that the method has been removed. How can I generate a reset password token and send it to a user?
Note: I don't want to send the default reset password email
Upvotes: 0
Views: 2966
Reputation: 29094
After a lot of digging into devise
's source code, I got it to work by doing this.
raw, enc = Devise.token_generator.generate(User, :reset_password_token)
@user.reset_password_token = enc
@user.reset_password_sent_at = Time.now.utc
if @user.save
UserMailer.welcome_email(@user, raw).deliver
..
Use raw
as the reset_password_token
Upvotes: 5