class User < ApplicationRecord has_many :fuel_entries, foreign_key: :updated_by_user_id, dependent: :restrict_with_error, inverse_of: :updated_by_user has_many :maintenance_entries, foreign_key: :updated_by_user_id, dependent: :restrict_with_error, inverse_of: :updated_by_user before_validation :normalize_email validates :name, presence: true validates :email, presence: true, uniqueness: { case_sensitive: false } private def normalize_email self.email = email.to_s.strip.downcase if email.present? end end