Rails uses :expire_after in the session options to specify when a sesssion should expire, but when Rack sets the cookie it expects to see :expires in the cookie options but Rails 2.3.11 fails to do the conversion so doesn't set the cookie expiry. To work around this, we set both options in the session options...
29 lines
787 B
Ruby
29 lines
787 B
Ruby
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[:expires] = Time.now + session[session_persistence_key]
|
|
request.session_options[:expire_after] = session[session_persistence_key]
|
|
end
|
|
end
|
|
end
|