Module: Geokit::ActsAsMappable

Extended by:
ActiveSupport::Concern
Defined in:
lib/geokit-rails/acts_as_mappable.rb,
lib/geokit-rails/acts_as_mappable/glue.rb,
lib/geokit-rails/acts_as_mappable/class_methods.rb

Defined Under Namespace

Modules: ClassMethods, Glue Classes: UnsupportedAdapter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.end_of_reflection_chain(through, klass) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/geokit-rails/acts_as_mappable.rb', line 58

def self.end_of_reflection_chain(through, klass)
  while through
    reflection = nil
    if through.is_a?(Hash)
      association, through = through.to_a.first
    else
      association, through = through, nil
    end

    if reflection = klass.reflect_on_association(association)
      klass = reflection.klass
    else
      raise ArgumentError, "You gave #{association} in :through, but I could not find it on #{klass}."
    end
  end

  reflection
end

Instance Method Details

#auto_geocode_addressObject

this is the callback for auto_geocoding



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/geokit-rails/acts_as_mappable.rb', line 44

def auto_geocode_address
  address=self.send(auto_geocode_field).to_s
  geo=Geokit::Geocoders::MultiGeocoder.geocode(address)

  if geo.success
    self.send("#{lat_column_name}=", geo.send(:"#{lat_column_name}"))
    self.send("#{lng_column_name}=", geo.send(:"#{lng_column_name}"))
  else
    errors.add(auto_geocode_field, auto_geocode_error_message)
  end

  geo.success
end