Rails dalli gem,加载会话ID的会话

时间:2011-01-07 23:26:46

标签: session load ruby-on-rails-3

如果我知道dalli_store用作会话存储时的会话ID,有没有办法获取会话信息?r

1 个答案:

答案 0 :(得分:1)

进入config / initializers / session_store.rb添加

mem_options = {
  :key         => '_your_session_key',
  :secret      =>  ....
}

ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, CMS::FlashSessionCookieMiddleware, mem_options[:key])

你的flash_session_cookie_middleware.rb应该包含:

require 'rack/utils'

  module CMS

  class FlashSessionCookieMiddleware
    def initialize(app, session_key = '_session_id')
      @app = app
      @session_key = session_key
    end

    def call(env)
      if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
        params = ::Rack::Utils.parse_query(env['QUERY_STRING'])
        env['HTTP_COOKIE'] = [@session_key, params[@session_key]].join('=').freeze unless params[@session_key].nil?
      end
      @app.call(env)
    end
  end

end