public
Description: A Rails plugin for expiring sessions on inactivity
Homepage: http://workswithruby.com/2008/10/session_lifetime-plugin
Clone URL: git://github.com/DefV/session_lifetime.git
name age message
file .gitignore Thu Oct 30 03:27:35 -0700 2008 Get rid of .DS_Store [DefV]
file MIT-LICENSE Thu Oct 30 03:27:02 -0700 2008 Initial Testless commit [DefV]
file README.rdoc Mon Nov 03 10:59:49 -0800 2008 Explain what to do when you want a certain cont... [DefV]
file init.rb Thu Oct 30 03:27:02 -0700 2008 Initial Testless commit [DefV]
directory lib/ Wed Feb 18 07:52:30 -0800 2009 Got rid of the cattr_accessors, added the redir... [DefV]
README.rdoc

SessionLifetime

SessionLifetime is a plugin which allows you to set a lifetime on your session. You can set it to expire the session 1 hour after the last activity.

Example

  class ApplicationController << ActionController::Base
    expires_session
  end

Or you can give some options:

  • :time - After how much time of inactivity should the session be invalidated. Default is 1 hour
  • :redirect_to - Where should we redirect the user to once their session has expired
  • :on_expiry - Takes a Proc or a lamba which gives you a callback after the session invalidation. This is useful for setting a flash message or something in the database.

    class ApplicationController << ActionController::Base

      expires_session :time => 2.hours, :redirect_to => '/login', :on_expiry => lambda {
        flash[:notice] = "Your session has been expired, and you have been logged out."
      }
    

    end

If you want a controller not to have expiring_session you can use skip_before_filter:

  class SessionController << ApplicationController
    skip_before_filter :check_session_lifetime, :only => [:new, :create]
  end

Missing something?

I wrote this plugin to solve the problems I had with default Rails session handling. If you have an additional need which you think would be great for this plugin, give me a shout at sessionlifetime@defv.be, or through GitHub, and I’ll be more then happy to implement your proposal.

Copyright © 2008 Jan De Poorter, released under the MIT license