Module: Geokit::ActsAsMappable

Extended by:
ActiveSupport::Concern
Defined in:
lib/geokit-rails/acts_as_mappable.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



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/geokit-rails/acts_as_mappable.rb', line 351

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



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/geokit-rails/acts_as_mappable.rb', line 337

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.lat)
    self.send("#{lng_column_name}=", geo.lng)
  else
    errors.add(auto_geocode_field, auto_geocode_error_message)
  end

  geo.success
end