2014-04-24 120 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'。但我不知道该怎么称呼它。 –