我得到这个错误一段时间,有些时候没有。这很奇怪。
错误:语法错误在或附近“)”LINE 1:SELECT locations。*,()as 距离“位置”ORDER ...
排队
nearby_locations.includes(:events).each do |location|
在我的仪表板控制器中
def home
nearby_locations = Location.with_distance_to(remote_ip).order('distance').limit(10)
@events = []
nearby_locations.includes(:events).each do |location|
@events += location.events.where("publish = true")
end
end
在我的Location.rb模型中
geocoded_by :address
extend Geocoder::Model::ActiveRecord
reverse_geocoded_by :latitude, :longitude
scope :with_distance_to, ->(point) { select("#{table_name}.*").select("(#{distance_from_sql(point)}) as distance") }
答案 0 :(得分:1)
要停止错误,您应该在使用remote_ip
上定义的范围之前验证dashboard_controller
中Location
是否存在。
def home
unless remote_ip.blank?
nearby_locations = Location.with_distance_to(remote_ip).order('distance').limit(10)
@events = []
nearby_locations.includes(:events).each do |location|
@events += location.events.where("publish = true")
end
end
end
要真正理解这个问题,首先要了解remote_ip
是如何空白并解决该问题。