Assuming your model is User:
User.with_reset_password_token(your_token_here)
Question
I'm trying to create password rules to devise recoverable password change. I did a super class via passwords_controller.rb, but I need to check the user role before aply the rules, but all that I have there is the reset_password_token.
Solution
OTHER TIPS
Older versions of devise don't contain this method: with_reset_password_token(your_token_here)
So you can create this method in your model:
def self.with_password_reset_token(password_reset_token)
generated_password_reset_token = Devise.token_generator.digest(self, :reset_password_token, password_reset_token)
return self.find_by(reset_password_token: generated_password_reset_token)
end
Then you can call this method from your model like this:
user = User.with_password_reset_token(your_token_here)
We are using user model here in the example.
To answer the title of your question it would simply be
User.find_by_reset_password_token(reset_password_token_here)
But your question is bit unclear beyond that.
Very late to the party here but User.find_by(reset_password_token: <token>)
works as well.