# How to destroy a session in the proper way

**URL:** <https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411>\
**Category:** Rails\
**Created:** [December 7, 2007, 12:13pm UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411 "2007-12-07T12:13:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 7, 2007, 12:13pm UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411/1 "2007-12-07T12:13:38Z")

</div>

Hi All,

i use a commend “session[‘user’] = nil” to destroy the session when the  
user log out from the system.

bt even though i destroy the session i can see all the temporary files  
that was created in my temp folder. so now i have a dought if i use my  
system to run in the actual envirnment my temp folder will fill with all  
the session temporary files.

so pls any one can tell how to get rid of this problem and is this the  
way to destroy sessions.

Thanks  
Nadeesha

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 7, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411/2 "2007-12-07T12:51:24Z")

</div>

if you use session[‘user’] = nil then it will only remove the session  
for the user session variable.

instead of that put reset\_session and it will remove every session  
information

On Dec 7, 11:13 am, Nadeesha M. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 7, 2007, 12:53pm UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411/3 "2007-12-07T12:53:44Z")

</div>

and yes use active record session then your tmp/session folder will be  
empty.

On Dec 7, 11:13 am, Nadeesha M. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 8, 2007, 7:46am UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411/4 "2007-12-08T07:46:17Z")

</div>

nas wrote:

> and yes use active record session then your tmp/session folder will be  
> empty.
> 
> On Dec 7, 11:13 am, Nadeesha M. \<rails-mailing-l…@andreas-

hi nas,

tried ur session reset\_session code it also working. bt still have the  
problem like the temp session file dose not get deleted.

also i did not got what is this use active record session thing is.  
pls need some advice

Thanks  
Nad

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 8, 2007, 11:36am UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411/5 "2007-12-08T11:36:25Z")

</div>

On 08 Dec 2007, at 11:30, Frederick C. wrote:

> > > and yes use active record session then your tmp/session folder  
> > > will be  
> > > empty.
> 
> The folder will be empty but you’ll have a growing sessions table.  
> Either way you need a cronjob (or pick your favourite mechanism for  
> scheduling scripts to run) that deletes sessions a some regular  
> interval.

… or you can just call a cleanup method at the login page depending  
on the amount of traffic your site gets, works just as well.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 8, 2007, 11:31am UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411/6 "2007-12-08T11:31:10Z")

</div>

On Dec 8, 6:46 am, Nadeesha M. \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> nas wrote:
> 
> > and yes use active record session then your tmp/session folder will be  
> > empty.

The folder will be empty but you’ll have a growing sessions table.  
Either way you need a cronjob (or pick your favourite mechanism for  
scheduling scripts to run) that deletes sessions a some regular  
interval.

Fred

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 8, 2007, 11:41am UTC](https://www.ruby-forum.com/t/how-to-destroy-a-session-in-the-proper-way/122411/7 "2007-12-08T11:41:49Z")

</div>

Peter De Berdt wrote:

> On 08 Dec 2007, at 11:30, Frederick C. wrote:
> 
> > > > and yes use active record session then your tmp/session folder  
> > > > will be  
> > > > empty.
> > 
> > The folder will be empty but you’ll have a growing sessions table.  
> > Either way you need a cronjob (or pick your favourite mechanism for  
> > scheduling scripts to run) that deletes sessions a some regular  
> > interval.
> 
> … or you can just call a cleanup method at the login page depending  
> on the amount of traffic your site gets, works just as well.
> 
> Best regards
> 
> Peter De Berdt

ok thanks a lot Pals
