2012-07-19 20 views
0

我在我的Rails應用程序中創建了多個測試用戶來測試登錄。他們通過設置會話自動登錄。在rails中刪除了一個用戶,但會話仍然存在 - 如何清除它?

一旦我感到滿意的用戶登錄,我走進了軌道控制檯,並刪除了用戶 User.last.delete

但是,現在當我嘗試加載本地主機:3000,我的瀏覽器仍在尋找用戶數14,我剛刪除的人。

ActiveRecord::RecordNotFound in StaticPagesController#home 

Couldn't find User with id=14 

app/controllers/application_controller.rb:7:in `current_user' 
app/views/static_pages/home.html.erb:2:in `_app_views_static_pages_home_html_erb___2558135612319095530_70269927858560' 

Request 

Parameters: 

None 

即使重新啓動服務器,並與rake db:reset完全清除數據庫沒有幫助---不應該這樣破壞任何會話問題告訴我的應用程序的外觀ID = 14?

+0

您刪除的用戶,但它看起來像會話仍然引用到它。你應該刪除localhost的cookie。這應該解決它。 – Zabba 2012-07-19 00:46:54

回答

0

如果清除cookie不起作用,您可以嘗試使用負責創建會話的控制器。 您sholud有方法,它破壞會話,例如:

def destroy 
    session[:user_id] = nil 
    redirect_to root_path, notice: 'Logged out' 
end 

添加一些路線,然後只需在瀏覽器中瀏覽到

localhost:3000/logout 
相關問題