mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 20:27:30 +02:00
WhiteIP: Replace empty string with nil
This commit is contained in:
parent
dc428b3c18
commit
d99dd477c6
1 changed files with 6 additions and 1 deletions
|
@ -4,8 +4,13 @@ class WhiteIp < ApplicationRecord
|
|||
|
||||
validate :valid_ipv4?
|
||||
validate :valid_ipv6?
|
||||
|
||||
validate :validate_ipv4_and_ipv6
|
||||
before_save :normalize_blank_values
|
||||
|
||||
def normalize_blank_values
|
||||
%i[ipv4 ipv6].each { |c| self[c].present? || self[c] = nil }
|
||||
end
|
||||
|
||||
def validate_ipv4_and_ipv6
|
||||
return if ipv4.present? || ipv6.present?
|
||||
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue