简体   繁体   中英

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, ie 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM