lib/roda/plugins/flash.rb in roda-3.9.0 vs lib/roda/plugins/flash.rb in roda-3.10.0
- old
+ new
@@ -89,19 +89,25 @@
module InstanceMethods
# Access the flash hash for the current request, loading
# it from the session if it is not already loaded.
def flash
- @_flash ||= FlashHash.new(session[:_flash])
+ # :_flash to support transparent upgrades from previous key
+ @_flash ||= FlashHash.new(session['_flash'] || (session['_flash'] = session.delete(:_flash)))
end
# If the routing doesn't raise an error, rotate the flash
# hash in the session so the next request has access to it.
def call
res = super
if f = @_flash
- session[:_flash] = f.next
+ f = f.next
+ if f.empty?
+ session.delete('_flash')
+ else
+ session['_flash'] = f
+ end
end
res
end
end