Files
nairobi/app/models/map_location.rb
Javi Martín 234a5108a4 Use strings for class_name
As mentioned in the Rails console:

DEPRECATION WARNING: Passing a class to the `class_name` is deprecated
and will raise an ArgumentError in Rails 5.2. It eagerloads more classes
than necessary and potentially creates circular dependencies. Please
pass the class name as a string.
2019-05-28 14:26:18 +02:00

30 lines
727 B
Ruby

class MapLocation < ApplicationRecord
belongs_to :proposal, touch: true
belongs_to :investment, class_name: "Budget::Investment", touch: true
validates :longitude, :latitude, :zoom, presence: true, numericality: true
def available?
latitude.present? && longitude.present? && zoom.present?
end
def json_data
{
investment_id: investment_id,
proposal_id: proposal_id,
lat: latitude,
long: longitude
}
end
def self.load_from_heading(heading)
map = new
map.zoom = Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM
map.latitude = heading.latitude.to_f if heading.latitude.present?
map.longitude = heading.longitude.to_f if heading.longitude.present?
map
end
end