mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Dynamic validations example
This commit is contained in:
parent
0c5b7c4cb8
commit
415f109d8f
7 changed files with 75 additions and 48 deletions
|
@ -127,8 +127,10 @@ class Domain < ActiveRecord::Base
|
|||
### VALIDATIONS ###
|
||||
|
||||
def validate_nameservers_count
|
||||
unless nameservers.length.between?(1, 13)
|
||||
errors.add(:nameservers, :out_of_range, {min: 1, max: 13})
|
||||
sg = SettingGroup.find_by(code: SettingGroup::DOMAIN_VALIDATION_CODE)
|
||||
min, max = sg.get(:ns_min_count).to_i, sg.get(:ns_max_count).to_i
|
||||
unless nameservers.length.between?(min, max)
|
||||
errors.add(:nameservers, :out_of_range, {min: min, max: max})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,4 +2,11 @@ class SettingGroup < ActiveRecord::Base
|
|||
has_many :settings
|
||||
|
||||
accepts_nested_attributes_for :settings
|
||||
|
||||
DOMAIN_VALIDATION_CODE = 'domain_validation'
|
||||
|
||||
def get(key)
|
||||
s = settings.find_by(code: key.to_s)
|
||||
s.try(:value)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue