2016-11-04 2 views
0

ich habe diesen Code:Rubin: Sortieren Array von einem Foat Feld

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]} 

Aber das Array sortiert nicht durch Entfernung eingereicht ... irgendwelche Vorschläge?

Antwort

2
nearPlaces.sort_by(&:distance) 
+0

ich habe diesen Fehler => 'Syntaxfehler, unerwartete &' – SaroVin

+0

@SaroVin es ist unmöglich :) –

+0

mehr Details => '_controller.rb: 23: Syntaxfehler, unerwartete & orderPlaces = nearPlaces.sort_by { &: distance}^' – SaroVin