ruby-on-railssessionruby-on-rails-4session-timeoutsession-store

Expiring Multiple Sessions at Different Times in Rails 4


I've created an application in Rails 4, and need to expire 3 different sessions at different time intervals, one every few minutes, one every hour, and one once per working day.

However, at the moment, all 3 of my sessions seem to expire at the same time, taking their expiration length from the smallest value of those set, i.e. every 5 minutes. Any idea what I'm doing wrong?

Currently, I've tried to set these expirations in the session store, like so:

Rails.application.config.session_store :cookie_store, key: 'current_customer', expire_after: 60.minutes 
Rails.application.config.session_store :cookie_store, key: 'staff_id', expire_after: 540.minutes
Rails.application.config.session_store :cookie_store, key: 'barcode_ids', expire_after: 5.minutes 

Thank you


Solution

  • In your code example you actually set one value for 3 times, and each time it is overwritten by the new value. So in fact it is using only the last line.

    Rails only creates one cookie per session for each user, and the other two you should create manually.