Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I force expire a session if a cart_id no longer exists?
    primarykey
    data
    text
    <p>I implemented a shopping cart into my app.</p> <p>In my <code>ApplicationController.rb</code>, I have this:</p> <pre><code>before_filter :initialize_cart def initialize_cart if session[:cart_id] @cart = Cart.find(session[:cart_id]) else @cart = Cart.create session[:cart_id] = @cart.id end end </code></pre> <p>I am using Devise, and have enabled <code>:timeoutable</code>.</p> <p>These are the configs in my <code>config/initializers/devise.rb</code>:</p> <pre><code> # ==&gt; Configuration for :timeoutable # The time you want to timeout the user session without activity. After this # time the user will be asked for credentials again. Default is 30 minutes. config.timeout_in = 30.minutes # If true, expires auth token on session timeout. config.expire_auth_token_on_timeout = true </code></pre> <p>The issue is that I occasionally want to sweep old carts. As it stands right now, once a cart hasn't been accessed in a while it gets deleted.</p> <p>However, when the user tries to login - if they haven't cleared cookies in a while - they get this error:</p> <pre><code>ActiveRecord::RecordNotFound at / Couldn't find Cart with id=51 </code></pre> <p>I checked the session object for a timestamp of creation or update and it doesn't have one - so I can't check the state of the session and delete the session if it is past 30 minutes or whatever.</p> <p>This is what the session object looks like:</p> <pre><code>&gt;&gt; session =&gt; {"session_id"=&gt;"57bkhjadksjfhaksjdhfca", "cart_id"=&gt;51, "_csrf_token"=&gt;"3823j42&amp;*&amp;@#lkjM+wKkagdabskdjfhba="} </code></pre> <p>How do I either check to see the if the session is recent (say the user - both logged in and non-logged in - has done something in the last hour) and then destroy it if it isn't?</p> <p>Or how do I fix this issue in any other way?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload