From 7f7da82aa0c161bfd00c790812aa2aa66bed23cf Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Sun, 20 Feb 2011 15:41:24 +0100 Subject: [PATCH] document sessions --- README.rdoc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.rdoc b/README.rdoc index c29fa075..807dbb80 100644 --- a/README.rdoc +++ b/README.rdoc @@ -724,6 +724,37 @@ route handlers and templates: bar(params[:name]) end +=== Using Sessions + +A session is used to keep state during requests. If activated, you have one +session hash per user session: + + enable :sessions + + get '/' do + "value = " << session[:value].inspect + end + + get '/:value' do + session[:value] = params[:value] + end + +Note that enable :sessions actually stores all data in a cookie. This +might not always be what you want (storing lots of data will increase your +traffic, for instance). You can use any Rack session middleware, in order to +do so, do *not* call enable :sessions, but instead pull in your +middleware of choice how you would any other middleware: + + use Rack::Session::Pool, :expire_after => 2592000 + + get '/' do + "value = " << session[:value].inspect + end + + get '/:value' do + session[:value] = params[:value] + end + === Halting To immediately stop a request within a filter or route use: