bievre_app/app/models/specific_map_item.rb
Caroline Girard dee35396f0 initial
2018-09-07 11:04:43 +02:00

39 lines
770 B
Ruby

class SpecificMapItem < ActiveRecord::Base
belongs_to :specific_map
validates :name, :presence => true
has_many :specific_map_item_cavs, :dependent => :destroy
has_many :cav_levels, :through => :specific_map_item_cavs
before_create do
self.geolocalise
end
def geolocalise
self.g_text = self.address.to_s+", "+self.cp.to_s+" "+self.city.to_s+", France"
@result = nil
result = Geocoder.search(self.g_text).each do |result|
if result.city and result.country
@result = result
break
end
end
if @result
self.g_latitude = @result.latitude
self.g_longitude = @result.longitude
end
end
reverse_geocoded_by :g_latitude, :g_longitude
end