I have a Sinatra webapp I've built using enable :sessions
where I access my session data with session[:mything]
.
I now want to store data on the server side (ie. with database based sessions) and I can't figure out how to use Rack::Session::Pool
, which appears to be the thing I need to use.
How do I go about converting my webapp for use with Pool?
I know I need to add the line
use Rack::Session::Pool
what comes next? — thanks in advance!
EDIT: Here's an example using cookie-based sessions:
require 'rubygems'
require 'sinatra'
enable :sessions
get '/' do
session.merge!(params)
session.inspect
end
Visit /?hi=there
then visit /
and you'll still see {'hi'=>'there'}
, as it's been stored in a cookie.
Simply replace the line enable :sessions
with use Rack::Session::Pool
.
All enable :session
does is adding Rack::Session::Cookie
to the stack (which you want to avoid). The session
helper will still work.
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