BikeBikeBike/app/models/location.rb

22 lines
776 B
Ruby
Raw Normal View History

2014-03-09 14:43:33 -06:00
class Location < ActiveRecord::Base
#attr_accessible :title, :country, :territory, :city, :street, :postal_code, :latitude, :longitude
2014-07-24 00:16:33 -06:00
has_many :locations_organization
has_many :organizations, :through => :locations_organization
2014-03-09 14:43:33 -06:00
geocoded_by :full_address
2014-07-24 00:16:33 -06:00
2014-03-09 14:43:33 -06:00
reverse_geocoded_by :latitude, :longitude, :address => :full_address
after_validation :geocode, if: ->(obj){ obj.country_changed? or obj.territory_changed? or obj.city_changed? or obj.street_changed? or obj.postal_code_changed? }
def full_address
addr = title
addr = (addr ? ', ' : '') + (street || '')
addr = (addr ? ', ' : '') + (city || '')
addr = (addr ? ', ' : '') + (territory || '')
addr = (addr ? ' ' : '') + (country || '')
addr = (addr ? ' ' : '') + (postal_code || '')
addr
end
end