Skip to content

HOWTO Enable and Use Sessions

karmi edited this page Sep 13, 2010 · 9 revisions

Sessions are disabled by default. Add the following at the top-level of your app to enable:

enable :sessions

The session Hash is then available in routes, filters, and error handlers:

get '/' do
  session["counter"] ||= 0
  session["counter"] += 1

  "You've seen this page #{session["counter"]} time(s)"
end

The Book includes additional detail on using Sessions:

http://sinatra.github.com/book.html#sessions

Clone this wiki locally