diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-25 15:30:47 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-25 15:31:02 -0700 |
commit | d14caa300c8d3af1e04c37811ae81c7e5f596ab0 (patch) | |
tree | f909c5fb3e8db53365d1be9412a2d17455e38219 /actionpack | |
parent | 58300772f30691f1220795eebacd2386f16a9706 (diff) | |
download | rails-d14caa300c8d3af1e04c37811ae81c7e5f596ab0.tar.gz rails-d14caa300c8d3af1e04c37811ae81c7e5f596ab0.tar.bz2 rails-d14caa300c8d3af1e04c37811ae81c7e5f596ab0.zip |
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
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/request.rb | 15 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/flash.rb | 13 |
2 files changed, 16 insertions, 12 deletions
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 |