2016-11-18 50 views
1

我想要创建一个方法(轨道上的红宝石)来遍历我从API(网址,名称,创建日期等)拉的照片哈希值,并只返回用户输入的正确参数中的日期。在散列表中,你有created_time作为键之一,这就是我所感兴趣的。有什么建议吗?Rails方法迭代通过照片的散列,并根据条件返回值

def pull_time 
    @pictures.map do |picture| 
    if picture.created_time >= @start_date && picture.created_time <= @end_date 
     return @pictures 
    end 
    end 
end 
+0

斗你想所有这一切就是按照上述条件的照片吗? –

回答

1

使用between

@pictures.select { |picture| picture.created_time.between?(@start_date, @end_date) }