you dont need to set a "session" variable for this, cookies work just fine. this really simple sinatra app should show you everything you would need to do.
Note there are jquery plugins to handle getting and setting cookie variables much better then just hard coding like I do here but the idea is the same:
require 'rubygems'
require 'sinatra'
get '/' do
#here is how you can set a cookie from sinatra
response.set_cookie("other_thing_id", 7)
# note: the next 2 things will go to the output on the command line but not to the html rendered in the browser
# check out whats in the cookie
puts "here is all the cookies: " +request.cookies
# get at that "thing_id" cookie that we set in the view after the first time they come to this page
puts "here is the thing_id in the cookies: " + request.cookies["thing_id"].to_i
# now go do something with it
# here is what the view would look like
'I am going to set a cookie <script> document.cookie = "thing_id=4" </script> here it is <script>alert(document.cookie)</script>'
end