2014-04-24 42 views
0

我在寫一個需要使用session_id銷燬任意會話的gem。Rails:使用session_id銷燬會話

目前我使用如下代碼

case Rails.application.config.session_store 
when ActionDispatch::Session::CacheStore 
    Rails.cache.delete("_session_id:#{session_id}") 
when ActionDispatch::Session::ActiveRecordStore 
    ActiveRecord::SessionStore.session_class.find(session_id).destroy 
when ActionDispatch::Session::CookieStore 
    # cannot remove a client-storage session 
end 

但我發現每一個SessionStoragedestroy_session(env, session_id, options)方法。我怎樣才能在腳本中調用這個方法? (不是在請求或任何控制器)

回答

0

如果你在數據庫中存儲會話,你可以試試這個在您的控制檯:

rake db:sessions:clear 

您還可以從以下摧毀整個會話您控制器:

reset_session 
+0

對不起,我沒有說清楚。我目前正在編寫一個需要通過session_id銷燬任意會話的gem。所以我想調用一些方法,比如'ActionDispatch :: Session :: CacheStore#destroy_session'。但我不知道該怎麼稱呼它。 –