InterviewSolution
| 1. |
How To Use Sessions In Sinatra? |
|
Answer» By default, Sessions are disabled in Sinatra.You need to enable them and then use the session hash from routes and views. Below code shows how to enable, set or GET a session in Sinatra. //Enabling Session enable :sessions get '/foo' do // SETTING session value session[:MESSAGE] = 'Hello WORLD!' redirect to('/bar') end get '/bar' do // getting session value session[:message] # => 'Hello World!' end By default, Sessions are disabled in Sinatra.You need to enable them and then use the session hash from routes and views. Below code shows how to enable, set or get a session in Sinatra. //Enabling Session enable :sessions get '/foo' do // setting session value session[:message] = 'Hello World!' redirect to('/bar') end get '/bar' do // getting session value session[:message] # => 'Hello World!' end |
|