thatsmesofia thatsmesofia - 1 year ago 71
Ruby Question

Rails method to iterate through hash of photos and return value according to criteria

I want to create a method (ruby on rails) to iterate through a hash of photos I am pulling from an API (url, name, date created etc) and return only the dates that are in the correct params the user inputs. Inside of the hash you have "created_time" as one of the keys, and that is what I am interested in. Any suggestions?

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

Answer Source

Use between: { |picture| picture.created_time.between?(@start_date, @end_date) }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download