Last active
May 5, 2024 13:06
-
-
Save kalmbach/5385621 to your computer and use it in GitHub Desktop.
Rack Middleware that implements Session Flash messages.
(session values that will be available just for the request) Usage:
use Rack::Session::Flash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rack | |
module Session | |
class Flash | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
dup.call!(env) | |
end | |
def call!(env) | |
env['rack.session'] || raise(RuntimeError, | |
'You\'re missing a session handler. ' + | |
'You can get started using Rack::Session::Cookie') | |
env['rack.session']['flash'] ||= {} | |
response = @app.call(env) | |
env['rack.session']['flash'].clear | |
response | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment