diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index de3abc56c..d1e4c08e3 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -904,23 +904,28 @@ module JamRuby rel = User.where(:musician => true) unless (instrument = params[:instrument]).blank? rel = rel.joins("RIGHT JOIN musicians_instruments AS minst ON minst.user_id = users.id") - .where(['minst.instrument_id = ?', instrument]) + .where(['minst.instrument_id = ? AND users.id IS NOT NULL', instrument]) end location_distance, location_city = params[:distance], params[:city] if location_distance && location_city - citylatlng = [] # FIXME: get the lat/lng for the city - rel = rel.within(location_distance, :origin => citylatlng) - + if geo = MaxMindGeo.where(:city => params[:city]).limit(1).first + citylatlng = [geo.lat, geo.lng] + rel = rel.within(location_distance, :origin => citylatlng) + end elsif current_user latlng = [] if current_user.lat.nil? - # FIXME: Lookup latlng from params[:remote_ip] + if params[:remote_ip] + if geo = MaxMindGeo.ip_lookup(params[:remote_ip]) + latlng = [geo.lat, geo.lng] + end + end else latlng = [current_user.lat, current_user.lng] end distance = location_distance || 50 - rel = rel.within(distance, :origin => latlng) + rel = rel.within(distance, :origin => latlng) unless latlng.blank? end case ordering = Search.order_param(params)