Devise第一次登录重定向 [英] Devise After first login redirect

查看:116
本文介绍了Devise第一次登录重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常 after_sign_up_path 将会工作,但现在我有确认,这就是垃圾邮件。

Normally after_sign_up_path would work but now that i have confirmations, this goes to the trash.

我正在寻找一种方法来重定向他的第一个登录中的用户,这意味着

I'm searching for a way to redirect a user on his FIRST SIGN IN, meaning that


  • sign_in_count == 0

  • sign_in_count == 0

last_sign_in == nil

last_sign_in == nil

所以我添加到我的 applications_controller.rb

def after_sign_in_path_for(user)
  if current_user.sign_in_count == 0
    welcome_path
  end
end

但当然这不行。

but of course this didn't work. What am i missing ?

推荐答案

测试后,我们发现Devise设置 sign_in_count ,这意味着它永远不会是 0 ,它将是 1 首次登录:

After testing, we found Devise sets the value of sign_in_count immediately after login, meaning that it's never going to be 0, it's going to be 1 for a first-time login:

#config/routes.rb
devise_for :users, controllers: { sessions: "sessions" }

#app/controllers/sessions_controller.rb
class SessionController < Devise::DeviseController

    def after_sign_in_path_for(resource)
        if resource.sign_in_count == 1
           welcome_path
        else
           root_path
        end
    end

end

这篇关于Devise第一次登录重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆