mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
Skip status when value blank
This commit is contained in:
parent
8d4a4c437b
commit
075cdc0f0d
2 changed files with 18 additions and 1 deletions
|
@ -19,6 +19,7 @@ class Admin::DomainsController < ApplicationController
|
||||||
flash[:notice] = I18n.t('shared.domain_added')
|
flash[:notice] = I18n.t('shared.domain_added')
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
else
|
else
|
||||||
|
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||||
flash.now[:alert] = I18n.t('shared.failed_to_add_domain')
|
flash.now[:alert] = I18n.t('shared.failed_to_add_domain')
|
||||||
render 'new'
|
render 'new'
|
||||||
end
|
end
|
||||||
|
@ -34,6 +35,8 @@ class Admin::DomainsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||||
|
|
||||||
params[:registrar] = @domain.registrar
|
params[:registrar] = @domain.registrar
|
||||||
params[:domain_owner_contact] = @domain.owner_contact
|
params[:domain_owner_contact] = @domain.owner_contact
|
||||||
end
|
end
|
||||||
|
@ -42,6 +45,7 @@ class Admin::DomainsController < ApplicationController
|
||||||
if @domain.update(domain_params)
|
if @domain.update(domain_params)
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
else
|
else
|
||||||
|
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||||
render 'edit'
|
render 'edit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Domain < ActiveRecord::Base
|
||||||
accepts_nested_attributes_for :nameservers, allow_destroy: true
|
accepts_nested_attributes_for :nameservers, allow_destroy: true
|
||||||
|
|
||||||
has_many :domain_statuses, dependent: :delete_all
|
has_many :domain_statuses, dependent: :delete_all
|
||||||
accepts_nested_attributes_for :domain_statuses, allow_destroy: true
|
accepts_nested_attributes_for :domain_statuses, allow_destroy: true, reject_if: proc {|attrs| attrs[:value].blank?}
|
||||||
|
|
||||||
has_many :domain_transfers, dependent: :delete_all
|
has_many :domain_transfers, dependent: :delete_all
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ class Domain < ActiveRecord::Base
|
||||||
validate :validate_nameservers_uniqueness, if: :new_record?
|
validate :validate_nameservers_uniqueness, if: :new_record?
|
||||||
validate :validate_tech_contacts_uniqueness, if: :new_record?
|
validate :validate_tech_contacts_uniqueness, if: :new_record?
|
||||||
validate :validate_admin_contacts_uniqueness, if: :new_record?
|
validate :validate_admin_contacts_uniqueness, if: :new_record?
|
||||||
|
validate :validate_domain_statuses_uniqueness, if: :new_record?
|
||||||
# validates_associated :nameservers
|
# validates_associated :nameservers
|
||||||
|
|
||||||
attr_accessor :adding_admin_contact
|
attr_accessor :adding_admin_contact
|
||||||
|
@ -149,6 +150,18 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_domain_statuses_uniqueness
|
||||||
|
validated = []
|
||||||
|
domain_statuses.each do |status|
|
||||||
|
next if status.value.blank?
|
||||||
|
existing = domain_statuses.select { |x| x.value == status.value }
|
||||||
|
next unless existing.length > 1
|
||||||
|
validated << status.value
|
||||||
|
errors.add(:'domain_statuses.value', 'duplicate')
|
||||||
|
status.errors.add(:value, :taken)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def validate_period
|
def validate_period
|
||||||
return unless period.present?
|
return unless period.present?
|
||||||
if period_unit == 'd'
|
if period_unit == 'd'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue