Ruby array not deleting all of the correct array elements -
a website have been developing bike share program returning funky results , not sure wrong 1 function. trying return of bikes available checked out.
def can_checked_out bikes = bike.order(:bike_id).all bikes.each |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 gets of bikes, orders them id number , iterates through each 1 see if should remove array returns. if bike nees repaired/more repair/is checked out or has not been inspected should deleting bike. using 20 bikes , reason numbers showing saying there when of bikes checked out.
any appreciated!
if checked methods db columns, can use selector in query:
bike.order(:bike_id).where(need_repair: false, addtional_repair_need: false, checked_out: false, passed_inspection: true)
but explain more cleanly problem.
Comments
Post a Comment