Created
October 12, 2011 15:48
-
-
Save mjtko/1281582 to your computer and use it in GitHub Desktop.
middleware that preserves flashes over multiple redirects
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
# use via this in application.rb: | |
# config.middleware.insert_after(ActionDispatch::Flash, FlashPreserver) | |
class FlashPreserver | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
flash = (session = env['rack.session']) && session['flash'] | |
@app.call(env).tap do |status,*rest| | |
flash.keep if flash && [301, 302, 307].include?(status) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment