Skip to content

Instantly share code, notes, and snippets.

@kalmbach
Last active December 16, 2015 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalmbach/5385621 to your computer and use it in GitHub Desktop.
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
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