Sessions
The default session store for Mack applications is Mack::SessionStore::Cookie. This uses encrypted cookies to store the session. If the session cookie can't be decrypted it will be deleted and a new session will be started.
There are 3 parameters that govern sessions as a whole in Mack, and one one that governs the cookie session store.
# This should be set by your application so that ALL instances of your application are using # the same secret key. If you do not set it a random key will be generated each time you start # your application. configatron.default_secret_key # This sets which session store you would like to use, :cookie, is the default. configatron.mack.session_store # True/False turns on/off sessions for your entire Mack application, true is the default. configatron.mack.use_sessions # Sets the expiry time of the cookie. The default is 4 hours. configatron.mack.cookie_session_store.expiry_time
The session can be retrieved off of the Mack::Request class, like such:
request.session # => Mack::Session
In controllers and views it can be retrieved with the session method.
The Mack::Session behaves slightly like a Hash attributes can be set and retrieved on the session like such:
@user = User.new(:id => 1) session[:user_id] = @user.id session[:user_id] # => 1