From 23e996afbc49ecf0479c52fac1848f3be194426a Mon Sep 17 00:00:00 2001 From: xx <1490923109@qq.com> Date: Sun, 25 Oct 2015 02:10:54 +0800 Subject: [PATCH] when coordinates is null return 0 in distance method --- app/models/project.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/project.rb b/app/models/project.rb index 18680e8..559bf30 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -5,6 +5,7 @@ class Project < ActiveRecord::Base def distance(coordinates) coordinates ||= [] + return 0 if coordinates.map(&:to_i) == [0, 0] num = Geocoder::Calculations.distance_between(coordinates, [lat.to_f, lon.to_f]).round(1) # "#{num} km" end