Search code examples
ruby-on-railscookiesexpired-cookies

How to modify cookie options after it's been set in rails?


I am developing a rails application. I just got stuck handling cookies. I have set my cookie in rails as follows.

(cookies[AUTH_TOKEN_NAME] = { value: auth_token, domain: domain }). 

But then I tried to change its option value by

cookies[AUTH_TOKEN_NAME]={expires: 24.hour.from_now}

But it failed. How do I modify its expires option after the cookie has already been set?


Solution

  • If multiple cookies of the same name match a given request URI, one is chosen by the browser. The more specific the path, the higher the precedence. However precedence based on other attributes, including the domain, is unspecified, and may vary between browsers.

    In your case i believe two cookies are generated by the same name.Try

    cookies[AUTH_TOKEN_NAME] = { value: auth_token, domain: domain, expires: 24.hour.from_now}
    

    as a replacement