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

37 lines
644 B
Ruby
Raw Permalink Normal View History

2019-09-03 09:43:24 -04:00
# frozen_string_literal: true
class Session < ApplicationRecord
################
# Associations #
################
belongs_to :account
2019-09-10 00:35:23 -04:00
#############
# Callbacks #
#############
before_validation :turn_nils_into_blanks
before_validation :strip_extra_spaces
2019-09-03 09:43:24 -04:00
###############
# Validations #
###############
2019-09-03 10:01:00 -04:00
validates :logged_at, presence: true
2019-09-03 09:43:24 -04:00
validates :ip_address, presence: true
2019-09-10 00:35:23 -04:00
2019-09-30 07:30:19 -04:00
validates :user_agent, allow_nil: true, good_big_text: true
2019-09-10 00:35:23 -04:00
private
def turn_nils_into_blanks
2019-09-29 09:23:06 -04:00
self.user_agent = nil if user_agent.blank?
2019-09-10 00:35:23 -04:00
end
def strip_extra_spaces
self.user_agent = user_agent&.strip
end
2019-09-03 09:43:24 -04:00
end