我不确定为什么,但我的 session 在每次请求时都会被清除。
这是我的代码
require 'rubygems'
require 'sinatra'
require 'sinatra/base'
require 'haml'
require 'facebook_oauth'
class MyClass < Sinatra::Base
set :logging, true
set :sessions, true
get "/auth/facebook_callback" do
// Do some facebook login which is fine
access_token = facebookClient.authorize(:code => params[:code])
session[:access_token] = access_token.token
session[:user] = facebookClient.me.info['name']
session[:id] = facebookClient.me.info["id"]
#print session by "pp session" I can still see all the sessions
redirect '/'
end
get '/' do
#print all the sessions again. And I can't see anything. The session_id is also different
end
end
最佳答案
为了保持 session 的一致性,您需要设置一个 session secret ,例如:
set :session_secret, 'super secret'
如果未设置,sinatra 会在应用程序启动时随机生成一个,shotgun 在每次请求之前都会重新启动应用程序。
关于ruby - Sinatra session 自动销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8957594/