I'm doing a flight-booking application in Rails and have successfully listed dates of flights as arrays.
However, I have a problem with duplicates. I've used a select_tag(:dates, options_for_select(@dates), which works, but I've got all these duplicate dates.
Heres the code for @dates.
@dates=Flight.all.map do |a|
dates=[]
unless dates.any? && dates.last[0]==a.flight_date_formatted
dates<<[a.flight_date_formatted, a.id]
end
end
This returns an array of arrays of the type of ["22/5/2016", 1]. I can't use unique because of the second element, in which the id is always different.
In the code I'm trying to access the last/first element of the array and get its [0] element, which would be "22/5/2016" and if it's equal to the current date then skip this iteration. Unfortunately it isn't working as I expect.
There are 7 flights and only 3 different Dates so it's not hard for it to catch at least one different.
How can I filter the duplicate records?