I'm exploring Sinatra and I want to use sessions but I don't want them to be stored in a Cookie, I found Rack::Session::Pool which works very well.
Now I want sessions to expire after a certain duration but I don't understand how to instanciate the Rack::Session::Pool and them use it in Sinatra.
Any Clue ?
Sinatra is quite powerful, the trick from The Wicked Flea didn't work but this did :
use Rack::Session::Pool, :domain => 'example.com', :expire_after => 60 * 60 * 24 * 365
Thanks !
In your rackup file:
%w(rubygems rack sinatra).each { |dependency| require dependency }
disable :run
require 'myapp'
sessioned = Rack::Session::Pool.new(
Sinatra::Application,
:domain => 'example.com',
:expire_after => 60 * 60 * 24 * 365 # expire after 1 year
)
run sessioned
To launch run rackup app.ru
, or use Passenger, etc. This ought to wrap your application in the session pool and enable its functionality. I don't entirely know why it doesn't need use like most other middleware.
Understand that I haven't tested this at all, I haven't had something that needed session pools yet. I wrote this from the documentation for Rack::Session::Pool, which had an example at the top of the page. So, I can't tell you exactly how to use it either.
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