Deleting the current session with Rack::Session::Cookie

与世无争的帅哥 提交于 2019-12-03 10:47:24

问题


I feel like I'm missing something obvious here, and I'm hoping that as soon as I post this someone will shame me with the google search link I was missing :-)

enable :sessions

get '/logout' do
  # What goes here to kill the session?
end

回答1:


Just use

session.clear

to destroy the session.




回答2:


It depends how you create your session. Simply you have to nulify session entry. Here is simple example, how to create and destroy sessions.

  get '/login' do
    session[:username] = params[:username]
    "logged in as #{session[:username]}"
  end

  get '/logout' do
    old_user = session[:username]
    session[:username] = nil
    "logged out #{old_user}"
  end

You can also check this example: https://gist.github.com/131401



来源:https://stackoverflow.com/questions/4252800/deleting-the-current-session-with-racksessioncookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!