简体   繁体   中英

How can I make my ActiveRecord objects only exist for 5 minutes in Ruby on Rails?

I've created a model called Request, which is created when one user makes a request with another user. I'd like each request to only exist for 5 minutes. Is this possible?

Couple of ways to do this ... you could add a Sweeper or delayed job to clear the values from the database periodically. Give each record a created_at, clear after 5 minutes.

Alternative would be to do this check when presenting the information to the user ... similar idea, have a created_at, when you check the pending requests for the current user you ignore or delete any that are older than 5 minutes.

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