简体   繁体   中英

Rails 3 cookies won't stay permanent

I've recently upgraded to Rails 3.0.7 (from Rails 2) and I've suddenly found my cookies are no longer working. Before I was able to set the expiration date and all was well. I'm aware of the new cookies.permanent way of doing things but that doesn't seem to work either (and my understanding is that the old way should work anyways).

Here's my code, it's very straight forward:

cookies[:remember_me_id] = { :value => user.id.to_s, :expires => 365.days.from_now }
cookies[:remember_me_code] = { :value => Digest::SHA256.hexdigest(user.cookie_code), :expires => 365.days.from_now }

Just to be 100% clear, I've tried this as well:

cookies.permanent[:remember_me_id] = user.id.to_s
cookies.permanent[:remember_me_code] = Digest:SHA256.hexdigest(user.cookie_code)

The cookies are created but the problem is they are set to expire when the browser closes. I've checked this in Firefox and IE. In Firefox when I go to view the cookie it says the expiration is when the browser closes. This is NOT what I want at all.

Is there something simple I'm missing here? Some new Rails 3 setting that must be put in place to make cookies persist?

I've been experiencing this same issue, but only when developing with WEBrick in an ms windows environment: Rails 3.0.5, ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32].

I find that cookie expiry works as expected when executing the same code on WEBrick running in my usual linux environment: Rails 3.0.5, ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]). Both methods outlined above (setting:expires explicitly or using the "permanent" accessor), appear to work on my linux box.

Because the issue appears to be isolated to the windows environment I didn't search exhaustively for a resolution... but a cursory search revealed no answer. Have you had any further luck with this issue?

Are you developing on windows and is switching dev environments an option for you? (not an ideal one obviously)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM