# Rails cookie javascript problem in IE6

**URL:** <https://www.ruby-forum.com/t/rails-cookie-javascript-problem-in-ie6/139168>\
**Category:** Rails\
**Created:** [May 31, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/rails-cookie-javascript-problem-in-ie6/139168 "2008-05-31T22:27:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [May 31, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/rails-cookie-javascript-problem-in-ie6/139168/1 "2008-05-31T22:27:39Z")

</div>

We’re trying to read cookies (set with rails), but we’re having  
huuuuuge problems reading them with javascript in IE6. For some  
reason, document.cookies is always nil. The cookies ARE set (we see  
them) but reading them in IE6 & javascript doesn’t work for some  
reason.

We set the cookies in rails like this in the controller:  
cookies[:auth\_token] = { :value =\> somevalue, :expires =\> somedate }

Console readout for setting the cookies:  
Cookie set: auth\_token=3df2e4d86b36f7c6410452fc48f68f65e0c86993;  
path=/; expires=Sat, 14 Jun 2008 20:23:24 GMT

The javascript function for reading the cookie:  
function readCookie(name)  
{  
var nameEQ = name + “=”;  
var ca = document.cookie.split(’;’);  
for(var i=0;i \< ca.length;i++)  
{  
var c = ca[i];  
while (c.charAt(0)==’ ')  
{  
c = c.substring(1,c.length);  
}  
if (c.indexOf(nameEQ) == 0)  
{  
return c.substring(nameEQ.length,c.length);  
}  
}  
return null;  
}

Has anyone ever had this problem, or better: know how to fix it?
