开发者

Rails dalli gem, load session with session id

is there a way to get the session info if i know the session id when dalli_store is used as the s开发者_开发知识库ession store???r


Into config/initializers/session_store.rb add

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

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

And your flash_session_cookie_middleware.rb should contain:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜