开发者

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

开发者 https://www.devze.com 2023-01-04 17:19 出处:网络
I\'ve created a model called Request, which is created when one user makes a req开发者_运维技巧uest with another user. I\'d like each request to only exist for 5 minutes. Is this possible?Couple of wa

I've created a model called Request, which is created when one user makes a req开发者_运维技巧uest 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号