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
2019-09-30 16:31:37 +05:00

36 lines
644 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, allow_nil: true, good_big_text: true
private
def turn_nils_into_blanks
self.user_agent = nil if user_agent.blank?
end
def strip_extra_spaces
self.user_agent = user_agent&.strip
end
end