Pluploadのflashで複数アップロードでcookieが送信されなくて困る
lib/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::Request.new(env).params
env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil?
end
@app.call(env)
end
end
----------------
config/initializers/session_store.rb
----------------
Rails.application.config.middleware.insert_before(
Rails.application.config.session_store,
FlashSessionCookieMiddleware,
Rails.application.config.session_options[:key]
)
----------------
flashのparamsに
----------------
{
authenticity_token : '<%= form_authenticity_token %>',
<%- session_key_name = Rails.application.config.session_options[:key] -%>
<%= "#{session_key_name} : '#{cookies[session_key_name]}'" %>
}
----------------