aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/flash.rb
diff options
context:
space:
mode:
authorSamuel Cochran <sj26@sj26.com>2015-01-29 23:18:55 +1100
committerSamuel Cochran <sj26@sj26.com>2015-01-29 23:18:55 +1100
commitf7adb34999eb4df7916102b60f5aa3f0ddc8210c (patch)
tree94019b9fcc8c227e41efa19226c8f8632c0f51f7 /actionpack/lib/action_dispatch/middleware/flash.rb
parent3a102d052803f7f066e648454297301310d69906 (diff)
downloadrails-f7adb34999eb4df7916102b60f5aa3f0ddc8210c.tar.gz
rails-f7adb34999eb4df7916102b60f5aa3f0ddc8210c.tar.bz2
rails-f7adb34999eb4df7916102b60f5aa3f0ddc8210c.zip
Discard from flash before persisting in session
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/flash.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/flash.rb34
1 files changed, 17 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb
index a7f95150a4..b1d402cd30 100644
--- a/actionpack/lib/action_dispatch/middleware/flash.rb
+++ b/actionpack/lib/action_dispatch/middleware/flash.rb
@@ -80,24 +80,24 @@ module ActionDispatch
include Enumerable
def self.from_session_value(value) #:nodoc:
- flash = case value
- when FlashHash # Rails 3.1, 3.2
- new(value.instance_variable_get(:@flashes), value.instance_variable_get(:@used))
- when Hash # Rails 4.0
- new(value['flashes'], value['discard'])
- else
- new
- end
-
- flash.tap(&:sweep)
- end
-
- # Builds a hash containing the discarded values and the hashes
- # representing the flashes.
- # If there are no values in @flashes, returns nil.
+ case value
+ when FlashHash # Rails 3.1, 3.2
+ flashes = value.instance_variable_get(:@flashes)
+ new(flashes, flashes.keys)
+ when Hash # Rails 4.0
+ flashes = value['flashes']
+ new(flashes, flashes.keys)
+ else
+ new
+ end
+ end
+
+ # Builds a hash containing the flashes to keep for the next request.
+ # If there are none to keep, returns nil.
def to_session_value #:nodoc:
- return nil if empty?
- {'discard' => @discard.to_a, 'flashes' => @flashes}
+ flashes_to_keep = @flashes.except(*@discard)
+ return nil if flashes_to_keep.empty?
+ {'flashes' => flashes_to_keep}
end
def initialize(flashes = {}, discard = []) #:nodoc: