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
Persistent cookies are cookies that are saved on your computer and are not deleted automatically when you quit your browser, unlike a session cookie, which is deleted when you leave your browser.
Rack::Session::Cookie provides simple cookie based session management. By default, the session is a Ruby Hash stored as base64 encoded marshalled data set to :key (default: rack. session). The object that encodes the session data is configurable and must respond to encode and decode .
To clear the whole thing use the reset_session method in a controller. Resets the session by clearing out all the objects stored within and initializing a new session object.
Just use
session.clear
to destroy the session.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With