2015-12-02 70 views
1

我正在使用Devise on Rails 4.1 我的問題是關於助手及其與會話的關係。 current_user:告訴您是否有用戶會話可供用戶使用。 user_signed_in:告訴你用戶是否被認證。devise rails current_user vs user_signed_in?

我不明白如果user_signed_in可以有一個current_user?是假的?

這兩種方法有什麼區別,它與會話有什麼關係。

THanks。 Richard Madson

回答

4

user_signed_in?被提供爲方便。如果user_signed_in?false,那麼您的說法是正確的,因此永遠不會有current_user

devise source code,我們可以看到:

def #{mapping}_signed_in? 
    !!current_#{mapping} 
end 

(其中user採取的#{mapping}的地方)

user_signed_in?只是返回的current_user的感實性,即,如果falsecurrent_usernil

相關問題