简体   繁体   中英

Rails3 / Sessions / Active_Record_Store / Signout --> How to delete the cookie and the record in the Sessions table?

Using active_record_store to store information relating to my users' sessions, and having a great time with how easy it is, but also finding that it is so easy that I am not taking the time to understand it.

I recently found that when users sign out of my site, nothing in the Sessions table is deleted, and so I have very quickly amassed a rather large Sessions table.

What I'd like to do is: Delete the record in the Sessions table when the user signs out AND delete the cookie on the user's computer. What do I have to add to my signout routine to accomplish this?

As of now, all that I'm doing is wiping the user id from the session data, which is clearly not sufficient. I thought I could just delete the record from Sessions by calling the destroy() method on the ActiveRecord object, but, I don't have the session ID. (Maybe I just don't know how to get it?)

我是铁杆的新手,但我建议你试试这个:

rake db:sessions:clear

只是因为这是google搜索“rails active_record_store clear table”时的最佳答案,以下是关于如何清除sessions-table的答案: https ://stackoverflow.com/a/10088725/1474934

 session[:user_id] = nil
 session[:username]= nil
 flash[:notice]= "You have been Logged out"
 redirect_to(:action => "login")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM