Rails 方法根据条件遍历照片的散列和 return 值
Rails method to iterate through hash of photos and return value according to criteria
我想创建一个方法(ruby on rails)来遍历我从 API(url,名称,创建日期等)和 return 只有用户输入的正确参数中的日期。在散列内部,你有 created_time
作为键之一,这就是我感兴趣的。有什么建议吗?
def pull_time
@pictures.map do |picture|
if picture.created_time >= @start_date && picture.created_time <= @end_date
return @pictures
end
end
end
使用between
:
@pictures.select { |picture| picture.created_time.between?(@start_date, @end_date) }
我想创建一个方法(ruby on rails)来遍历我从 API(url,名称,创建日期等)和 return 只有用户输入的正确参数中的日期。在散列内部,你有 created_time
作为键之一,这就是我感兴趣的。有什么建议吗?
def pull_time
@pictures.map do |picture|
if picture.created_time >= @start_date && picture.created_time <= @end_date
return @pictures
end
end
end
使用between
:
@pictures.select { |picture| picture.created_time.between?(@start_date, @end_date) }