2

如何在我的自定义会话控制器上确定用户是第一次登录,我希望能够创建一个会话并重定向到welcome#index它是否是第一次,否则它将被重定向到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(resource)我想要的,但我无法找到如何确定用户之前是否使用设计登录

4

1 回答 1

10

你应该可以用:sign_in_count列做到这一点。如果为 0,则表示用户之前没有登录

举个例子

redirect_to ((current_user.sign_in_count == 0) ? path1 : path2 ) 
于 2013-02-07T04:57:02.363 回答