]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/session-persistence/README.rdoc
Require arel 2.0.8 or later to avoid problems with Postgres enums
[rails.git] / vendor / plugins / session-persistence / README.rdoc
1 = Session Persistence
2
3 Rails 3 plugin that lets you set how long you want your session to be persisted/remembered.
4
5  session_expires_after 2.weeks
6  session_expires_automatically # also aliased to expire_session
7    
8 The timespan will reset on every request. If you set it to 2 weeks, and the user returns after 1 week, the session will be refreshed and last 2 weeks again. If the user returns after 3 weeks, the session will be reset.
9
10 A call to session_expires_automatically will return to a normal automatical expiry cookie, that will expire when the browser is closed.
11
12 Note: I haven't tested the plugin with memcache session storage, but it should work there as well.
13
14 = Usage
15    
16 Here's an example sessions controller in a Rails 3 application.
17
18  class SessionsController < ApplicationController
19   def create
20     session_expires_after 2.weeks if params[:remember_me]
21     
22     # ..normal auth goes here..
23     # for example
24     user = User.authenticate(params[:username], params[:password])
25     if user
26       session[:user] = user.id
27     else
28       # ..
29     end
30   end
31   
32   def destroy
33     session_expires_automatically
34     
35     # ..unauthorize here..
36     # for example
37     session[:user] = nil
38     redirect_to root_path
39   end
40  end