2010-11-12 25 views
3

我希望所有到我的網站的用戶都有默認的「訪客」會話。我正在使用Devise。我的所有設計代碼都適用於註冊用戶,但我也有一個「訪客」用戶的用戶記錄。如何創建默認的「訪客」會話,以便設計助手current_user將顯示我的訪客用戶?

我想要做的就是以用戶的身份自動登錄某人,這樣在我的視圖和其他地方,對Devise的current_user的調用不會失敗。

我從9月底開始嘗試爲此找到答案。我甚至無法在Devise郵件列表上得到答覆。

回答

3
def set_user 
    if current_user.blank? 
    user = User.where(:email => "[email protected]").first 
    if user.blank? 
     redirect_to new_user_registration_path 
    else 
     sign_in(user) # Why was this so hard to find out? I had to read all of the Devise code. 
    end 
    end 
end 
+0

這是一個before_filter在你的應用程序控制器或什麼? – davekaro 2012-04-03 19:53:54

相關問題