SaroVin SaroVin - 1 month ago 13
Ruby Question

Ruby: Sort array by a foat field

i have this code:

response = Place.all

nearPlaces = []
for el in response
distance = el.distance_to([41.9097306,12.2558141])
if distance < 20
el.distance = distance
nearPlaces.push(el)
end
end

orderPlaces = nearPlaces.sort_by{|e| e[:distance]}


But the array is not sort by distance filed...any suggestion?

Answer
nearPlaces.sort_by(&:distance)