A website I have been developing for a bike share program is returning funky results and I am not sure what is wrong with this one function. I am trying to return all of the bikes that are available to be checked out.
def can_checked_out
bikes = Bike.order(:bike_id).all
bikes.each do |bike|
bikes.delete bike if bike.need_repair or bike.addtional_repair_need or bike.checked_out or !bike.passed_inspection
end
bikes
end
So it gets all of the bikes, orders them by their id number and iterates through each one to see if it should remove it from the array that it returns. If the bike nees to be repaired/more repair/is checked out or has not been inspected then it should be deleting the bike. Currently I am using 20 bikes and for some reason the even numbers are showing up saying they are there when all of the bikes are checked out.
Any help would be appreciated!