# Unable to set expiry date on cookies

**URL:** <https://www.ruby-forum.com/t/unable-to-set-expiry-date-on-cookies/189768>\
**Category:** Rails\
**Created:** [June 7, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/unable-to-set-expiry-date-on-cookies/189768 "2010-06-07T12:12:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 7, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/unable-to-set-expiry-date-on-cookies/189768/1 "2010-06-07T12:12:28Z")

</div>

cookies[:user\_info] = {:value =\> “whatever”, :expires =\>  
30.days.from\_now }

When I check in the browser, the cookie will expire “at end of session”  
Oo What’s happening? How to set the cookie’s date then?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 7, 2010, 12:36pm UTC](https://www.ruby-forum.com/t/unable-to-set-expiry-date-on-cookies/189768/2 "2010-06-07T12:36:16Z")

</div>

On 07 Jun 2010, at 12:12, Fernando P. wrote:

> cookies[:user\_info] = {:value =\> “whatever”, :expires =\>  
> 30.days.from\_now }
> 
> When I check in the browser, the cookie will expire “at end of  
> session”  
> Oo What’s happening? How to set the cookie’s date then?

The code looks fine. Are you sure you haven’t set your browser to  
“Private Browsing”? Because that would result in all cookies expiring  
at the end of the session.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 7, 2010, 1:12pm UTC](https://www.ruby-forum.com/t/unable-to-set-expiry-date-on-cookies/189768/3 "2010-06-07T13:12:25Z")

</div>

Hi Peter,

I just checked and my browser is not in private mode. In the response I  
can see that a header is set-cookie with a date forward in time, so  
something strange is happening here.

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 7, 2010, 1:26pm UTC](https://www.ruby-forum.com/t/unable-to-set-expiry-date-on-cookies/189768/4 "2010-06-07T13:26:00Z")

</div>

Ok my bad. I tested in Safari and it works perfectly, so there is  
something blocking in Firefox 3.6, but the expiry date setting works  
with other sites, so I don’t understand what’s happening.

Is there some edge case scenario I’m missing here? Should all options of  
the cookie be set?

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 7, 2010, 1:36pm UTC](https://www.ruby-forum.com/t/unable-to-set-expiry-date-on-cookies/189768/5 "2010-06-07T13:36:15Z")

</div>

"So stupid! I just noticed that in FF the option “Keep until: I close  
Firefox” was set, I must have done that inadvertently.

Sorry for my silly problem.
