Created
July 21, 2009 21:29
-
-
Save vishnugopal/151602 to your computer and use it in GitHub Desktop.
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
# Originally from | |
# http://github.com/i2av/sinatra-flash/blob/7bb1f5e0a1093d4f114bbe8074bb1a7792bc5ab1/app.rb | |
# but heavily modified | |
module Sinatra | |
module Flash | |
module RedirectHelper | |
def redirect(uri, *args) | |
session[:_flash] = flash unless flash.empty? | |
status 302 | |
response['Location'] = uri | |
halt(*args) | |
end | |
end | |
module FlashHelper | |
def flash | |
@_flash ||= {} | |
end | |
end | |
def self.registered(app) | |
app.helpers RedirectHelper | |
app.helpers FlashHelper | |
app.enable :sessions | |
app.before do | |
@_flash, session[:_flash] = session[:_flash], nil if session[:_flash] | |
end | |
end | |
end | |
register Flash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment