简体   繁体   English

如何使我的ActiveRecord对象在Ruby on Rails中仅存在5分钟?

[英]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. 我希望每个请求仅存在5分钟。 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. 给每条记录一个created_at,5分钟后清除。

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. 替代方法是在向用户提供信息时执行此检查...类似的想法,创建一个at_at,当您检查当前用户的待处理请求时,您会忽略或删除任何早于5分钟的请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将ActiveRecord Create用于Ruby on Rails的多个记录? - how can I use ActiveRecord Create for multiple records Ruby on Rails? 如何在Ruby脚本的Rails中使用现有的ActiveRecord模型 - How can I use existing Activerecord model in rails in ruby script 如何在 Rails 中插入一堆 ActiveRecord 对象和关系? - How can I upsert a bunch of ActiveRecord objects and relationships in Rails? Rails5如何使用ActiveRecord Relation对象构建提要 - Rails5 How can I build a feed with ActiveRecord Relation objects 如何通过铁轨交叉两个ActiveRecord关系对象? - How can i intersection two ActiveRecord Relation objects by rails? Rails / ActiveRecord - 我怎样才能使这更简洁? - Rails/ActiveRecord - How can I make this more concise? 如何在我的rails应用程序中测试ActiveRecord :: RecordNotFound? - How can I test ActiveRecord::RecordNotFound in my rails app? 在 Ruby on Rails 中,如何保存许多引用同一类的其他实例的 ActiveRecord 对象? - In Ruby on Rails, how do I save many ActiveRecord objects that have references to other instances of the same class? 如何使我的Ruby on Rails 2.3.4应用程序“Rails 3-ready” - How can I make my Ruby on Rails 2.3.4 application “Rails 3-ready” Ruby on Rails :(入门)如何使我的样式表(在public / stylesheet文件夹中)被布局使用? - Ruby on Rails: (Beginner) How can I make my style sheet (in public/stylesheet folder) be used by my layouts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM