Fixed ransack admin search

This commit is contained in:
Sergei Tsoganov 2023-04-06 13:54:03 +03:00
parent ae384e4e64
commit aa8d8c35e8
9 changed files with 34 additions and 20 deletions

View file

@ -3,7 +3,7 @@ class DomainNameValidator < ActiveModel::EachValidator
# rubocop:disable Metrics/LineLength
def validate_each(record, attribute, value)
if !self.class.validate_format(value)
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :invalid))
record.errors.add(attribute, options[:message] || record.errors.generate_message(attribute, :invalid))
elsif !self.class.validate_blocked(value)
record.errors.add(:base, :domain_name_blocked)
end
@ -12,6 +12,7 @@ class DomainNameValidator < ActiveModel::EachValidator
class << self
def validate_format(value)
return true unless value
value = value.mb_chars.downcase.strip
origins = DNS::Zone.origins
@ -25,6 +26,7 @@ class DomainNameValidator < ActiveModel::EachValidator
if value[2] == '-' && value[3] == '-'
regexp = /\Axn--[a-zA-Z0-9-]{0,59}\.#{general_domains}\z/
return false unless value.match?(regexp)
value = SimpleIDN.to_unicode(value).mb_chars.downcase.strip
end