dawarich/app/models/track.rb
2025-07-03 20:18:18 +02:00

15 lines
488 B
Ruby

# frozen_string_literal: true
class Track < ApplicationRecord
belongs_to :user
has_many :points, dependent: :nullify
validates :start_at, :end_at, :original_path, presence: true
validates :distance, :avg_speed, :duration, numericality: { greater_than: 0 }
validates :elevation_gain, :elevation_loss, :elevation_max, :elevation_min,
numericality: { greater_than_or_equal_to: 0 }
def calculate_path
Tracks::BuildPath.new(points.pluck(:lonlat)).call
end
end