mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 08:52:04 +02:00
Attach nameservers with attributes
This commit is contained in:
parent
356835bebf
commit
d46640713b
6 changed files with 79 additions and 3 deletions
|
@ -63,8 +63,20 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def attach_nameservers(ns_list)
|
||||
ns_list.each do |x|
|
||||
self.nameservers.build(hostname: x)
|
||||
ns_list.each do |ns|
|
||||
#ns with detailed attributes
|
||||
if ns.is_a?(Hash)
|
||||
attrs = {hostname: ns[:hostName]}
|
||||
|
||||
ns[:hostAddr].each do |ip|
|
||||
attrs[:ip] = ip unless attrs[:ip]
|
||||
end if ns[:hostAddr]
|
||||
|
||||
self.nameservers.build(attrs)
|
||||
#ns with just hostname
|
||||
else
|
||||
self.nameservers.build(hostname: ns)
|
||||
end
|
||||
end
|
||||
|
||||
save
|
||||
|
@ -76,6 +88,14 @@ class Domain < ActiveRecord::Base
|
|||
errors.empty?
|
||||
end
|
||||
|
||||
# def validate_nameservers
|
||||
# nameservers.each do |x|
|
||||
# x.errors.each do |err|
|
||||
# errors.add(:nameservers)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
def add_child_collection_errors(attr_key, epp_obj_name)
|
||||
send(attr_key).each do |obj|
|
||||
obj.errors.keys.each do |key|
|
||||
|
|
|
@ -3,4 +3,5 @@ class Nameserver < ActiveRecord::Base
|
|||
has_and_belongs_to_many :domains
|
||||
|
||||
validates :hostname, hostname: true
|
||||
validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true}
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue