In the past when I’ve needed Rails-like session flash in a Sinatra app, I had to hand roll my own (which, admittedly, is pretty fun) and add it as a helper. But now it’s a much better idea to use Rack::Flash.
First, install Rack::Flash if you don’t have it already:
$ sudo gem install nakajima-rack-flash
And a quick demo app:
require 'rubygems' require 'sinatra' require 'rack-flash' use Rack::Session::Cookie use Rack::Flash get '/' do flash[:notice] = "Hello from rack-flash" redirect '/show-flash' end get '/show-flash' do flash[:notice] end
Notice that if you reload ‘/show-flash’ the session flash message disappears.
For more information on Rack::Flash:
* http://github.com/nakajima/rack-flash/
* http://blog.admoolabs.com/2009/03/20/rackflash/
Image may be NSFW.
Clik here to view.

Clik here to view.
