9

我有一个 Sinatra Web 应用enable :sessions程序,我使用session[:mything].

我现在想在服务器端存储数据(即使用基于数据库的会话),但我不知道如何使用Rack::Session::Pool,这似乎是我需要使用的东西。

如何将我的 web 应用程序转换为与 Pool 一起使用?

我知道我需要添加该行

use Rack::Session::Pool

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

编辑:这是使用基于 cookie 的会话的示例:

require 'rubygems'
require 'sinatra'

enable :sessions

get '/' do
  session.merge!(params)
  session.inspect
end

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

4

1 回答 1

12

只需将行替换enable :sessionsuse Rack::Session::Pool. 所做enable :session的只是添加Rack::Session::Cookie到堆栈中(您要避免)。session助手仍然可以工作。

于 2010-07-29T05:04:36.347 回答