设计首先使用rails登录 [英] devise first login with rails
本文介绍了设计首先使用rails登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在我的自定义会话控制器上确定用户是第一次登录,我想要创建一个会话并重定向到 welcome#index
如果它的第一次,它将重定向到 root_url
。
How can I determine on my custom session controller that the user is the first time login, I want to be able to create a session and to redirect to welcome#index
if its the first time else it would be redirected to root_url
.
我有的代码跟随
class MysessionsController < Devise::SessionsController
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end
protected
def after_sign_up_path_for(resource)
"http://google.com"
end
end
我知道我需要定制 after_sign_up_path_for(资源)
到我想要的,但是我无法确定用户是否在设计之前或之后登录
I know I need to custom after_sign_up_path_for(resource)
to what I want but I cant find how to determine if the user has sign in before or not with devise
推荐答案
你应该能够使用:sign_in_count
列。如果这是0,这意味着用户没有在
you should be able to do this with :sign_in_count
column. if this is 0 it means user has not sign in before
之前登录。举个例子
redirect_to ((current_user.sign_in_count == 0) ? path1 : path2 )
这篇关于设计首先使用rails登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文