1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/session.rb

36 lines
634 B
Ruby

# frozen_string_literal: true
class Session < ApplicationRecord
################
# Associations #
################
belongs_to :account
#############
# Callbacks #
#############
before_validation :turn_nils_into_blanks
before_validation :strip_extra_spaces
###############
# Validations #
###############
validates :logged_at, presence: true
validates :ip_address, presence: true
validates :user_agent, length: { maximum: 10_000 }
private
def turn_nils_into_blanks
self.user_agent = '' if user_agent.blank?
end
def strip_extra_spaces
self.user_agent = user_agent&.strip
end
end