mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 14:36:22 +02:00
Added validation for one only IP
This commit is contained in:
parent
bf3d971d7c
commit
18cd6f5046
2 changed files with 8 additions and 0 deletions
|
@ -5,6 +5,7 @@ class WhiteIp < ApplicationRecord
|
|||
validate :valid_ipv4?
|
||||
validate :valid_ipv6?
|
||||
validate :validate_ipv4_and_ipv6
|
||||
validate :validate_only_one_ip
|
||||
before_save :normalize_blank_values
|
||||
|
||||
def normalize_blank_values
|
||||
|
@ -17,6 +18,12 @@ class WhiteIp < ApplicationRecord
|
|||
errors.add(:base, I18n.t(:ipv4_or_ipv6_must_be_present))
|
||||
end
|
||||
|
||||
def validate_only_one_ip
|
||||
return unless ipv4.present? && ipv6.present?
|
||||
|
||||
errors.add(:base, I18n.t(:ip_must_be_one))
|
||||
end
|
||||
|
||||
def valid_ipv4?
|
||||
return if ipv4.blank?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue