【发布时间】:2014-08-12 20:57:34
【问题描述】:
我在我的 Location 模型上的项目中使用 Geocoder gem,该模型有一个 Venue,我想搜索指定纬度和经度附近的场地,并按位置距离对其进行排序。现在我这样搜索:
location_ids = Location.near([lat, lng], 1, units: :km).map(&:id)
venues = Venue.where("location_id IN (?)", location_ids)
我知道我可以做.map(&:venue),这将直接给我场地,但在此之后我在我的控制器中链接一个查询,这样做会产生一个Array而不是ActiveRecord::Relation,我可以继续链接查询在。
如何让我的场地按位置距离排序?
【问题讨论】:
标签: ruby-on-rails activerecord geocoding rails-geocoder