Module: ActiveRecord::Geocodable::Base

Defined in:
lib/active_record_geocodable/base.rb

Instance Method Summary collapse

Instance Method Details

#is_geocodable(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/active_record_geocodable/base.rb', line 5

def is_geocodable(options = {})
  include ActiveRecord::Geocodable::Model
  options = {:geocode => true}.merge(options)
  if options[:require]
    validates_presence_of :lat
    validates_presence_of :lng
    validates_numericality_of :lat
    validates_numericality_of :lng
    options[:geocode] = true
  end
  before_validation :geocode_complete_address if options[:geocode]
  named_scope :geocoded, :conditions => "#{table_name}.lat IS NOT NULL AND #{table_name}.lng IS NOT NULL"
end