gpt4 book ai didi

ruby-on-rails - 检查数组中的元素是否在最后 5 秒内被创建

转载 作者:数据小太阳 更新时间:2023-10-29 08:16:30 25 4
gpt4 key购买 nike

我有一个数组@user.photos,它将返回如下内容:

[#<Photo id: 53, photo_file_name: "Freedom-Tower", 
photo_content_type: "image/jpeg", photo_file_size: 1937702,
photo_updated_at: "2013-04-23 23:57:22", user_id: 1,
created_at: "2013-04-23 23:57:23", updated_at: "2013-04-23 23:57:23">,
#<Photo id: 52, photo_file_name: "sunset-Courtsey",
photo_content_type: "image/jpeg", photo_file_size: 1937702,
photo_updated_at: "2013-04-23 23:51:22", user_id: 1,
created_at: "2013-04-23 23:51:24", updated_at: "2013-04-23 23:51:24">

我想创建一个条件来检查用户最近是否创建了照片

类似于:@user.photos.any? { |x| x.created_at btw Time.now..-5 秒}??

最佳答案

你可以使用 5.seconds.ago:

@user.photos.any? {|x| x.created_at > 5.seconds.ago }

关于ruby-on-rails - 检查数组中的元素是否在最后 5 秒内被创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16225335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com