我正在使用devise gem进行身份验证。

在我的应用程序中,管理员将创建用户,因此我希望在管理员创建用户时用户的重置密码链接。

这是我的动作:

def create
   @user = User.new(user_params)
   @user.password = '123123123'
   @user.password_confirmation = '123123123'
   if @user.save
         @user.update_attributes(:confirmation_token => nil,:confirmed_at => Time.now,:reset_password_token => (0...16).map{(65+rand(26)).chr}.join,:reset_password_sent_at => Time.now)
       UserMailer.user_link(@user).deliver
       redirect_to users_path
     else
    render :action => "new"
   end
end


这是我重置用户密码的链接



但是当我打开链接并更新密码时,我得到的重置密码令牌无效。

最佳答案

您可以使用user.send_reset_password_instructions

10-07 12:14
查看更多