# Duration of session

**URL:** <https://www.ruby-forum.com/t/duration-of-session/171367>\
**Category:** Rails\
**Created:** [July 1, 2009, 7:57am UTC](https://www.ruby-forum.com/t/duration-of-session/171367 "2009-07-01T07:57:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiahong\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/3d9bf3/32.png) [@Xiahong\_G](https://www.ruby-forum.com/u/Xiahong_G)\
**Post date:** [July 1, 2009, 7:57am UTC](https://www.ruby-forum.com/t/duration-of-session/171367/1 "2009-07-01T07:57:09Z")

</div>

Hi everyone,

how to set the duration of a session? Does  
"ActionController::Base.session\_options[:new\_session] = … " work?  
Another question is if i am using database for session storage, when a  
session expires, will rails automatically remove the session record  
from database for me?

thanks in advance,  
xiahong

---

<div class="post-metadata">

**Author:** ![Xiahong\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/3d9bf3/32.png) [@Xiahong\_G](https://www.ruby-forum.com/u/Xiahong_G)\
**Post date:** [July 1, 2009, 4:09pm UTC](https://www.ruby-forum.com/t/duration-of-session/171367/2 "2009-07-01T16:09:21Z")

</div>

On 1 Jul 2009, at 01:56, Xiahong G. wrote:

> Hi everyone,
> 
> how to set the duration of a session? Does  
> "ActionController::Base.session\_options[:new\_session] = … " work?  
> Another question is if i am using database for session storage, when a  
> session expires, will rails automatically remove the session record  
> from database for me?

Nope. sessions never expire in that sense: the cookie containing the  
session id will die when the user exits their browser but your app  
does not (and in general cannot) know about that. It’s up to you to  
periodically clean out old rows from the sessions table.

Fred

---

<div class="post-metadata">

**Author:** ![Xiahong\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/3d9bf3/32.png) [@Xiahong\_G](https://www.ruby-forum.com/u/Xiahong_G)\
**Post date:** [July 2, 2009, 1:42am UTC](https://www.ruby-forum.com/t/duration-of-session/171367/3 "2009-07-02T01:42:34Z")

</div>

Assume session is deleted before the cookie holding its id expires, what  
happens when client contacts server with this session id? does rails  
allocate a new session with a different ID to replace this old session?

2009/7/1 Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
