diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-25 15:35:34 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-09-25 15:35:34 -0700 |
commit | ca324a0d9080660dc9c1803f90976cecb81b5f58 (patch) | |
tree | cc0d0df92d1fef7da6706ed8b4687530175587ba /actionpack/lib | |
parent | d14caa300c8d3af1e04c37811ae81c7e5f596ab0 (diff) | |
download | rails-ca324a0d9080660dc9c1803f90976cecb81b5f58.tar.gz rails-ca324a0d9080660dc9c1803f90976cecb81b5f58.tar.bz2 rails-ca324a0d9080660dc9c1803f90976cecb81b5f58.zip |
commit the flash after the controller finishes being serviced
Committing the flash needs to happen in order for the session to be
written correctly, so lets guarantee that it actually does happen.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/request.rb | 15 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/flash.rb | 26 |
3 files changed, 17 insertions, 25 deletions
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 3d72755f1d..beeaae9d0c 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -187,6 +187,7 @@ module ActionController set_request!(request) set_response!(response) process(name) + request.commit_flash to_a end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index f9fa57ecdc..eaa7e88b34 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -277,21 +277,6 @@ 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 dcf39ff8ef..a5269b7219 100644 --- a/actionpack/lib/action_dispatch/middleware/flash.rb +++ b/actionpack/lib/action_dispatch/middleware/flash.rb @@ -18,6 +18,21 @@ module ActionDispatch def flash_hash # :nodoc: get_header Flash::KEY end + + def commit_flash # :nodoc: + 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 end # The flash provides a way to pass temporary primitive-types (String, Array, Hash) between actions. Anything you place in the flash will be exposed @@ -268,15 +283,6 @@ module ActionDispatch end end - def initialize(app) - @app = app - end - - def call(env) - req = ActionDispatch::Request.new env - @app.call(env) - ensure - req.commit_flash - end + def self.new(app) app; end end end |