Add a plugin to handle session persistence. This is based on the

plugin at http://github.com/augustl/session-persistence but modified
to work with rails 2 rather than rails 3.
This commit is contained in:
Tom Hughes 2010-02-25 16:39:51 +00:00
parent 345ac0bd1a
commit 60f145f13e
5 changed files with 134 additions and 0 deletions

View file

@ -0,0 +1,30 @@
module SessionPersistence
private
# Override this method if you don't want to use session[:_remember_for].
def session_persistence_key
:_remember_for
end
# Persist the session.
#
# session_expires_after 1.hour
# session_expires_after 2.weeks
def session_expires_after(seconds)
session[session_persistence_key] = seconds
end
# Expire the session.
def session_expires_automatically
session.delete(session_persistence_key)
end
alias_method :expire_session, :session_expires_automatically
def _persist_session
if session[session_persistence_key]
request.session_options = request.session_options.dup
request.session_options[:expire_after] = session[session_persistence_key]
request.session_options.freeze
end
end
end