位置有:lat和:lng用于' geokit-rails'我正在运行Rails 4。
是否可以对在指定位置范围内具有曲目的不同集合执行查询?
class Location < ActiveRecord::Base
belongs_to :locatable, polymorphic: true
acts_as_mappable
end
class Tracks < ActiveRecord::Base
has_one :location, as: :locatable
belongs_to :collection
end
class Collection < ActiveRecord::Base
belongs_to :user
has_many :tracks
end
答案 0 :(得分:0)
要在grokit-rails中使用polymorphic,你必须通过:: location添加acts_as_mappable到你的Tracks模型:
class Tracks < ActiveRecord::Base
has_one :location, as: :locatable
acts_as_mappable through: :location
belongs_to :collection
end
查询必须是:
@collection.tracks.joins(:location).within(distance, :origin => @origin)