我有这段代码:
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]}
但阵列不是按距离提出的......任何建议?
答案 0 :(得分:2)
nearPlaces.sort_by(&:distance)