views:

332

answers:

1

I'm using swfupload's most recent version, 2.2.0 and rails 2.3.3. Having seen a number of statements to the effect that I would have to replace CGI::Session.initialize with a chunk of code to extract the session from key-value pairs injected into my form url, I incorporated the code segment into my environment.rb:

require 'cgi'
class CGI::Session
    alias original_initialize initialize
    def initialize(request, option = {})
        session_key = option['session_key'] || '_session_id'
        query_string = if (qs = request.env_table["QUERY_STRING"]) and qs != ""
            qs
        elsif (ru = request.env_table["REQUEST_URI"][0..-1]).include?("?")
            ru[(ru.index("?") + 1)..-1]
        end
        if query_string and query_string.include?(session_key)
            option['session_id'] = query_string.scan(/#{session_key}=(.*?)(&.*?)*$/).flatten.first
        end
        original_initialize(request, option)
    end
end

I do see the session info being correctly packed into the form parameters as files are uploaded, but the above code is never firing to bring the session info out of the database.

What's the secret sauce to get from params-packed session id and authenticity tokens (they're not being picked up from the params, either)?

+1  A: 

Rack middleware to the rescue

JimNeath
Considering how close I am to getting this working and how much time I have invested in it, I would prefer to get the answer to the original question if at all possible. I took a look a the rack middleware page and while it gives a working example in code, there is not a running example that one can examine for reference. So again, I'd rather get my current issue resolved before scrapping the entire thing and going to something new. Thanks, though. I'll keep it as my next option.
As far as I'm aware the whole CGI cookie thing won't work with the version of rails you're using as it now uses rack.
JimNeath