Created
May 30, 2014 14:43
-
-
Save atsheehan/de1f105174eb4c166262 to your computer and use it in GitHub Desktop.
Using session persistence with Sinatra.
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
require 'sinatra' | |
# Be sure to set an environment variable containing your secret key. | |
# This will be used to encrypt the cookies that are sent to the client. | |
# | |
# $ export SECRET_TOKEN=super_secret_key_goes_here | |
use Rack::Session::Cookie, secret: ENV['SECRET_TOKEN'] | |
get '/' do | |
if session[:visit_count] | |
session[:visit_count] += 1 | |
"You've visited this page #{session[:visit_count]} time(s)." | |
else | |
session[:visit_count] = 1 | |
"This is your first time here, welcome!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment