我正在使用Uploadify 2.1.4和rails 2.3.8。我試圖應用FlashSessionCookieMiddleware修復程序,該修復程序應該在uploadify的基於Flash的請求期間維護會話信息。我讀了一些這些指南的應用後,此修復程序:Uploadify,Flash會話和Rails 2.3.8
然而,我的會話信息仍然沒有被結轉。下面就來看看,在我的應用程序配置:
# config/environment.rb
config.load_paths += %W(#{RAILS_ROOT}/config/middleware)
...
# config/middleware/flash_session_cookie_middleware.rb
require 'rack/utils'
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
ActionController::Dispatcher.middleware.insert_before(ActionController::Base.session_store, FlashSessionCookieMiddleware, ActionController::Base.session_options[:key])
...
// My Uploadify JS
'fileDataName' : 'file',
'queueID' : 'fileQueue',
'auto' : true,
'multi' : true,
'method' : 'get',
'scriptData' : { session_key: '<%= request.session_options[:key] %>'}
我中間件代碼加載正確的,下面是耙中間件顯示:
use Rack::Lock
use ActionController::Failsafe
use FlashSessionCookieMiddleware, "_my_app_session"
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActiveRecord::SessionStore, #<Proc:[email protected](eval):8>
use ActionController::ParamsParser
use Rack::MethodOverride
use Rack::Head
use ActionController::StringCoercion
run ActionController::Dispatcher.new
然後,我嘗試測試了,如果最後一個請求具有有效的會話/ cookie的信息:
# In Controller
logger.info "Session: #{session.inspect}"
其中在日誌/ development.log只打印一個空的哈希:
Session: {}
[嗅探]任何人都可以看到我做錯了什麼?
哎呀,忘記標記接受了。您的解決方案運行良好,謝謝! – dhulihan 2011-06-08 19:50:42