Files
car-tracker/app/models/fuel_entry.rb
T
2026-09-15 20:28:07 -06:00

19 lines
599 B
Ruby

class FuelEntry < ApplicationRecord
belongs_to :vehicle
belongs_to :updated_by_user, class_name: "User"
validates :odometer, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :gallons_pumped, presence: true, numericality: { greater_than: 0 }
validates :price_paid, presence: true, numericality: { greater_than: 0 }
validates :date, presence: true
validate :date_cannot_be_in_the_future
private
def date_cannot_be_in_the_future
return if date.blank? || date <= Date.current
errors.add(:date, "can't be in the future")
end
end