Rack :: Session ::与Sinatra的游泳池

JP.*_*JP. 9 ruby session rack sinatra

我有一个Sinatra webapp,我用enable :sessions它来访问我的会话数据session[:mything].

我现在想在服务器端存储数据(即使用基于数据库的会话),我无法弄清楚如何使用Rack::Session::Pool,这似乎是我需要使用的东西.

如何转换我的webapp以用于Pool?

我知道我需要添加这条线

use Rack::Session::Pool
Run Code Online (Sandbox Code Playgroud)

接下来是什么?- 提前致谢!

编辑:这是一个使用基于cookie的会话的例子:

require 'rubygems'
require 'sinatra'

enable :sessions

get '/' do
  session.merge!(params)
  session.inspect
end
Run Code Online (Sandbox Code Playgroud)

访问/?hi=there然后访问/,你仍然会看到{'hi'=>'there'},因为它已存储在cookie中.

Kon*_*ase 12

只需更换线路enable :sessionsuse Rack::Session::Pool.一切enable :session都是添加Rack::Session::Cookie到堆栈(您要避免).该session助手将仍然有效.