Module: CollectiveIdea::Acts::Geocodable::ClassMethods

Defined in:
lib/acts_as_geocodable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_geocodable(options = {}) ⇒ Object

Make a model geocodable.

class Event < ActiveRecord::Base
  acts_as_geocodable
end

Options

  • :address: A hash that maps geocodable attirbutes (:street, :locality, :region, :postal_code, :country) to your model’s address fields, or a symbol to store the entire address in one field

  • :normalize_address: If set to true, you address fields will be updated using the address fields returned by the geocoder. (Default is false)

  • :units: Default units-:miles or :kilometers-used for distance calculations and queries. (Default is :miles)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/acts_as_geocodable.rb', line 30

def acts_as_geocodable(options = {})
  options = {
    :address => {
      :street => :street, :locality => :locality, :region => :region,
      :postal_code => :postal_code, :country => :country},
    :normalize_address => false,
    :distance_column => 'distance',
    :units => :miles
  }.merge(options)
  
  write_inheritable_attribute :acts_as_geocodable_options, options
  class_inheritable_reader :acts_as_geocodable_options
  
  define_callbacks :after_geocoding
  
  has_one :geocoding, :as => :geocodable, :include => :geocode, :dependent => :destroy
  
  after_save :prepare_attach_geocode          
  
  
  include CollectiveIdea::Acts::Geocodable::InstanceMethods
  extend CollectiveIdea::Acts::Geocodable::SingletonMethods
end