2017-05-04 46 views
0

我目前在做一个使用设计宝石的项目。注册,确认电子邮件以及登录都运行良好。但在忘记密码,我遇到了这个错误..我试图通过悬停“更改我的密码”文本检查令牌http://localhost:3000/rails/mailers/user_mailer/reset_password_instructions收到的令牌是相同的在我的表1个错误禁止该用户被保存:重置密码令牌无效

注意:我遵循的指令我有一个关于该reset_password文件

重置密码指令

<p>Hello <%= @resource.email %>!</p> 

<p>Someone has requested a link to change your password. You can do this through the link below.</p> 

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p> 

<p>If you didn't request this, please ignore this email.</p> 
<p>Your password won't change until you access the link above and create a new one.</p> 

用户梅勒预览

搜索
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer 
class UserMailerPreview < ActionMailer::Preview 

    def confirmation_instructions 
     @user = User.last 
     @getUser = User.find(@user) 
     @token = @getUser.confirmation_token 
     Devise::Mailer.confirmation_instructions(@user, @token) 
    end 

    def reset_password_instructions 
     @user = User.last 
     @getUser = User.find(@user) 
     @token = @getUser.reset_password_token 
     Devise::Mailer.reset_password_instructions(@user,@token) 
     end 
end 

问题:我该如何解决这类错误?

+0

Umm..is之前'resetting'密码的用户'confirmed'? –

+0

Yess ..我在重置密码之前确认了它 – Angel

+0

请分享您看到的确切错误.. –

回答

0

在user_mailer_preview的文件和reset_password_instructions的方法尝试添加该

def reset_password_instructions 
     query = "SELECT * FROM users 
      WHERE reset_password_token IS NOT NULL 
      ORDER by reset_password_sent_at DESC" 
     user = User.find_by_sql(query).first 
     token = user.send(:set_reset_password_token) 
     Devise::Mailer.reset_password_instructions(user, token) 

    end