Using Rack :: Session :: Pool with Sinatra

I am learning Sinatra and I want to use sessions, but I do not want them to be stored in Cookies, I found Rack :: Session :: Pool, which works very well.

Now I want the sessions to expire after a certain duration, but I don’t understand how to create the Rack :: Session :: Pool pool, and they use it in Sinatra.

Any clue?

+6
ruby ruby-on-rails sinatra
source share
2 answers

In your registry 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 run run rackup app.ru or use Passenger, etc. This should bring your application to the session pool and enable its functionality. I do not quite understand why this should not be used, like most other middlewares.

Understand that I have not tested this at all, I have not yet had what is needed for session pools. I wrote this from the documentation for Rack :: Session :: Pool, which had an example at the top of the page. Therefore, I can’t say exactly how to use it.

+5
source share

Sinatra is pretty strong, The Wicked Flea's trick didn't work, but it happened:

 use Rack::Session::Pool, :domain => 'example.com', :expire_after => 60 * 60 * 24 * 365 

Thanks!

+10
source share

All Articles