为了方便起见,我有一个只想使用.within等的类。
这就是我所做的。
# This is the class i want the scopes on
class Thing < ActiveRecord::Base
has_one :location, :as => :locatable
acts_as_mappable :through => :location
end
# My Location class
class Location < ActiveRecord::Base
belongs_to :locatable, :polymorphic => true
acts_as_mappable :default_units => :miles,
:default_formula => :sphere,
:distance_field_name => :distance,
:lat_column_name => :lat,
:lng_column_name => :lng
validates :lat , numericality: { greater_than_or_equal_to: -90, less_than_or_equal_to: 90 }
validates :lng, numericality: { greater_than_or_equal_to: -180, less_than_or_equal_to: 180 }
end
无论出于何种原因,我都无法在Thing
上使用act_as_mappable范围。
NoMethodError: undefined method `within' for #<Thing:0x007f9a561cecb8>
但是我可以使用Location.within(N,location)