app/models/concerns/mappable.rb in rocket_cms-0.5.19 vs app/models/concerns/mappable.rb in rocket_cms-0.5.20
- old
+ new
@@ -1,23 +1,30 @@
module Mappable
extend ActiveSupport::Concern
included do
- include Geocoder::Model::Mongoid
if RocketCMS.mongoid?
+ include Geocoder::Model::Mongoid
field :coordinates, type: Array
field :address, type: String
field :map_address, type: String
field :map_hint, type: String
field :lat, type: Float
field :lon, type: Float
+ else
+ def coordinates
+ if latitude.nil? || longitude.nil?
+ nil
+ else
+ [longitude, latitude]
+ end
+ end
end
- geocoded_by :geo_address
after_validation do
if geo_address.blank?
self.coordinates = nil
else
@@ -52,9 +59,11 @@
end
def has_map?
(!lat.blank? && !lon.blank?) || !coordinates.nil?
end
+
+ geocoded_by :geo_address
def to_map
{
id: id.to_s,
hint: map_hint,