2013-02-07 55 views
1

我如何確定我的自定義會話控制器,該用戶是第一次登錄,我想能夠創建一個會話,並重定向到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)到我想要什麼,但我不能找到如何確定用戶是否有之前登錄,或不符合設計

代碼
+0

'after_sign_up_path_for'確定用戶註冊後指向的頁面,這顯然會是他們第一次登錄(因爲它是直接註冊後)。 –

+0

那麼我的代碼有效嗎? – Jseb

+0

您可能必須將'after_sign_up_path_for'移動到自定義註冊控制器(而不是會話)。甚至將其移至ApplicationController。 –

回答

10

你應該可以用:sign_in_count這一欄來做到這一點。如果是0則意味着用戶之前

還沒有登錄,因此,作爲一個例子

redirect_to ((current_user.sign_in_count == 0) ? path1 : path2)