Made nearest method work with nil home lat/lon.
authorJohn McKerrell <john@mckerrell.net>
Sat, 5 May 2007 13:37:13 +0000 (13:37 +0000)
committerJohn McKerrell <john@mckerrell.net>
Sat, 5 May 2007 13:37:13 +0000 (13:37 +0000)
app/models/user.rb

index ce12755dfcd77162bcd47d4844226d8038673aba..887dcb388ea7eced6506608adb356cff9c3f7b78 100644 (file)
@@ -61,7 +61,11 @@ class User < ActiveRecord::Base
   
   def nearby(lat_range=1, lon_range=1)
      
-      nearby = User.find(:all,  :conditions => "#{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and  #{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and data_public = 1") 
+      if self.home_lon and self.home_lat 
+          nearby = User.find(:all,  :conditions => "#{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and  #{self.home_lon} > home_lon - #{lon_range} and #{self.home_lon} < home_lon + #{lon_range} and data_public = 1") 
+      else
+          nearby = []
+      end
       return nearby
   end