ruby - Are there any basic examples of Rack::Session::Cookie usage? -
i can't find simple examples using rack::session::cookie
, able store information in cookie, , access on later requests , have expire.
these examples i've been able find:
- how set/get session vars in rack app?
- http://rack.rubyforge.org/doc/classes/rack/session/cookie.html
here's i'm getting:
use rack::session::cookie, :key => 'rack.session', :domain => 'foo.com', :path => '/', :expire_after => 2592000, :secret => 'change_me'
and setting/retrieving:
env['rack.session'][:msg]="hello rack"
i can't find other guides or examples setup of this. can help?
you have setup cookie in question. not sure if means else "setup".
instead of env['rack.session']
can use session[key]
simplification.
session[:key] = "vaue" # set value session[:key] # return value
simple sinatra example
require 'sinatra' set :sessions, true '/' session[:key_set] = "set" "hello" end "/sess" session[:key_set] end
update
i believe wasn't working because had set invalid domain. had strip off :domain => 'foo.com',
. btw sinatra wraps rack cookie , exposes session
helper. above code worked fine me. believe following code should work expected.
require 'sinatra' use rack::session::cookie, :key => 'rack.session', :expire_after => 2592000, :secret => 'change_me' '/' msg = params["msg"] || "not set" env["rack.session"][:msg] = msg "hello" end "/sess" request.session["msg"] end
- set session value
msg
access root or/
defaults 'not set' if pass?msg=somestring
should set msg new value. - access
/sess
check whats in session.
you can take cues how set/get session vars in rack app?
Comments
Post a Comment