Rails cookie setting expires in 1 day

Looking through the docs here http://api.rubyonrails.org/classes/ActionDispatch/Cookies.html and setting the Rails cookie as follows:

cookies[:votes_left] = { :value => 3, :expires => 24.hours.from_now }

In my browser (Chrome) it reports the correct value, but gives me an Invalid Date in the Expires column (Network> Cookies).

Am I setting the date incorrectly? I tried variations of the Time object, but I get the same result, a correctly priced cookie with an invalid expiration .

+6
source share
1 answer

I tested it myself, and I see no problems with your code. As @Nevir said, check the correctness of your server clock. The only problem with this, if this is the wrong server time and the actual determination of the validity period until today, it will not set a cookie.

Try adding Rails.logger 24.hours.from_now to see what it outputs.

But yes, you set expires parameter correctly.

0
source

All Articles