From d14caa300c8d3af1e04c37811ae81c7e5f596ab0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 25 Sep 2015 15:30:47 -0700 Subject: move flash committing to the request object. I'm doing this so that we can commit the flash to the session object Out of Band of the flash middleware --- actionpack/lib/action_dispatch/http/request.rb | 15 +++++++++++++++ actionpack/lib/action_dispatch/middleware/flash.rb | 13 +------------ 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index eaa7e88b34..f9fa57ecdc 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -277,6 +277,21 @@ module ActionDispatch set_header ACTION_DISPATCH_REQUEST_ID, id end + def commit_flash + session = self.session || {} + flash_hash = self.flash_hash + + if flash_hash && (flash_hash.present? || session.key?('flash')) + session["flash"] = flash_hash.to_session_value + self.flash = flash_hash.dup + end + + if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?) + session.key?('flash') && session['flash'].nil? + session.delete('flash') + end + end + alias_method :uuid, :request_id # Returns the lowercase name of the HTTP server software. diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb index 014b7bee61..dcf39ff8ef 100644 --- a/actionpack/lib/action_dispatch/middleware/flash.rb +++ b/actionpack/lib/action_dispatch/middleware/flash.rb @@ -276,18 +276,7 @@ module ActionDispatch req = ActionDispatch::Request.new env @app.call(env) ensure - session = req.session || {} - flash_hash = req.flash_hash - - if flash_hash && (flash_hash.present? || session.key?('flash')) - session["flash"] = flash_hash.to_session_value - req.flash = flash_hash.dup - end - - if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?) - session.key?('flash') && session['flash'].nil? - session.delete('flash') - end + req.commit_flash end end end -- cgit v1.2.3