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