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.
source share