Skip to content

Instantly share code, notes, and snippets.

@vishnugopal
Created July 21, 2009 21:29
Show Gist options
  • Save vishnugopal/151602 to your computer and use it in GitHub Desktop.
Save vishnugopal/151602 to your computer and use it in GitHub Desktop.
# 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