# IE7 Cookies not persisting. Please help

**URL:** <https://www.ruby-forum.com/t/ie7-cookies-not-persisting-please-help/170870>\
**Category:** Rails\
**Created:** [June 23, 2009, 8:58pm UTC](https://www.ruby-forum.com/t/ie7-cookies-not-persisting-please-help/170870 "2009-06-23T20:58:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@Shannon](https://www.ruby-forum.com/u/Shannon)\
**Post date:** [June 23, 2009, 8:58pm UTC](https://www.ruby-forum.com/t/ie7-cookies-not-persisting-please-help/170870/1 "2009-06-23T20:58:59Z")

</div>

I’m new to cookies and rails so I apologize for my ignorance. I’m  
using Javascript to store persistent cookies using the following code  
(taken from the O’Reilly Javascript book):

Cookie.prototype.store = function( daysToLive, path, domain, secure )  
{  
var cookieval = “” ;

for ( var prop in this )  
{  
// Ignore properties wiht names that begin with the ‘$’ and also  
methods  
if ( ( prop.charAt(0) == ‘$’ ) || ( ( typeof this[prop]) ==  
‘function’ ) )  
continue ;

```
if ( cookieval != "" ) cookieval += '&' ;

cookieval += prop + ':' + encodeURIComponent( this[prop] ) ;

```

}  
var cookie = this.$name + ‘=’ + cookieval ;

if ( daysToLive || daysToLive == 0 )  
{  
cookie += “; max-age=” + (daysToLive_24_60\*60) ;  
}

if ( path ) cookie += “; path=” + path ;  
if ( domain ) cookie += “; domain=” + domain ;  
if ( secure ) cookie += “; secure” ;

// Now store the cookie by setting the Document.cookie property  
document.cookie = cookie ;  
}

This works fine in Firefox but in IE7 it seems to work like a session  
cookie. As soon as I close the browser it doesn’t exist.

I’m certain it’s something in Rails that I’m missing.

Thanks in advance for the help!

---

<div class="post-metadata">

**Author:** ![Shannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@Shannon](https://www.ruby-forum.com/u/Shannon)\
**Post date:** [June 23, 2009, 9:59pm UTC](https://www.ruby-forum.com/t/ie7-cookies-not-persisting-please-help/170870/2 "2009-06-23T21:59:26Z")

</div>

A few more details:

- I don’t have any other cookies for the domain
- There is not an underscore in the domain/subdomain
- My privacy setting are at their lowest (accept all cookies)
- The cookie is there and accessible until I close the browser and  
restart
- I’m sure there’s a simple Rails reason for all of this. I don’t  
want to have to persist the session to make this work, is that even  
possible in Rails?

Thanks again.

---

<div class="post-metadata">

**Author:** ![Shannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@Shannon](https://www.ruby-forum.com/u/Shannon)\
**Post date:** [July 19, 2009, 9:59pm UTC](https://www.ruby-forum.com/t/ie7-cookies-not-persisting-please-help/170870/3 "2009-07-19T21:59:25Z")

</div>

Try the depricated expires attribute instead of max-age, which is not  
supported by IE. expires differs from max-age in that it sets a date  
(UTC) instead of a duration.
