Tuesday 3 September 2013

Sinatra with sessions using Rack::Session::Pool

Sinatra with sessions using Rack::Session::Pool

I am having a problem with Sinatra using Rack::Session::Pool for storing
session information. What I want to do is to 'post' some data by appending
information to the session hash using 'POST /dataset', and then retrieve
it by using 'GET /dataset' and returning the content of 'session' hash.
When I try to return the value though, the 'session' hash does not contain
the :message key
require 'sinatra/base'
class Trial < Sinatra::Base
use Rack::Session::Pool
post '/dataset' do
puts session.inspect
session[:message] = params[:data]
puts "message now: #{session[:message]}"
puts session.inspect
end
get '/dataset' do
puts "post message: #{session[:message]}"
puts session.inspect
session[:message]
end
end
Trial.run!
I know this looks trivial, but still I can't get it to work...

No comments:

Post a Comment