# Session expire

**URL:** <https://www.ruby-forum.com/t/session-expire/141607>\
**Category:** Rails\
**Created:** [June 27, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/session-expire/141607 "2008-06-27T17:10:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [June 27, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/session-expire/141607/1 "2008-06-27T17:10:23Z")

</div>

Hi all,

I have set a session session to expire after an hour by doing:  
session[:expire] = { :expires =\> 1.hour.from\_now }  
What I would like to do is have it so that session gets reset back an  
hour whenever a new page is loaded. If, however, the session variable  
has expired and the user tries to load a page I want my app to kick them  
back to a loggin page. I have tried to achieve this by saying:

if !(session[:expire].blank? \< 0.hour.from\_now)  
session[:expire] = { :expires =\> 0.25.hour.from\_now }  
end

However, it doesn’t like the session[:expire]. It gives me:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.[]

even though I am saying if session is blank. Is there another way to do  
this. Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [June 29, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/session-expire/141607/2 "2008-06-29T12:05:01Z")

</div>

Have a look at the sliding\_session\_timeout plugin:  
[http://www.elctech.com/2007/10/29/sliding-session-timeout](http://www.elctech.com/2007/10/29/sliding-session-timeout)

On Jun 28, 3:10 am, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [June 30, 2008, 5:52am UTC](https://www.ruby-forum.com/t/session-expire/141607/3 "2008-06-30T05:52:34Z")

</div>

Chris B. wrote:

> Have a look at the sliding\_session\_timeout plugin:  
> [Elctech.com is for sale | HugeDomains](http://www.elctech.com/2007/10/29/sliding-session-timeout)
> 
> On Jun 28, 3:10ï¿½am, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

session :session\_expires =\> 10.minutes.from\_now

jst do this in ur application.rb and it will be applicable to ur whole  
application…It will work the same way u want… no need to do necoding  
for it

Hope this helps

Thanks

Dhaval P.  
Software Engineer  
Ruby on Rails

> **[RailsHouse : Ruby on Rails Development & Consulting, Waterloo, Canada](https://railshouse.com)**
>
> RailsHouse is Waterloo, Ontario based Ruby on Rails Consultancy firm which provides RoR Development, Migration, Staffing, Maintenace and Support Services

sales(AT)railshouse(DOT)com
