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



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/geokit-rails/acts_as_mappable.rb', line 362

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



348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/geokit-rails/acts_as_mappable.rb', line 348

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