111396946-validates

This commit is contained in:
Stas 2016-02-03 17:17:38 +02:00
parent 2ab5d8500a
commit f31db65d2c
6 changed files with 20 additions and 7 deletions

View file

@ -19,7 +19,15 @@ class Admin::BlockedDomainsController < AdminController
def create def create
abort @domain = BlockedDomain.new(blocked_domain_params)
if @domain.save
flash[:notice] = I18n.t('domain_added')
redirect_to admin_blocked_domains_path
else
flash.now[:alert] = I18n.t('failed_to_add_domain')
render 'new'
end
end end
@ -35,7 +43,7 @@ class Admin::BlockedDomainsController < AdminController
end end
def blocked_params def blocked_domain_params
params.require(:blocked_domain).permit(:name) params.require(:blocked_domain).permit(:name)
end end

View file

@ -21,7 +21,7 @@ class Admin::ReservedDomainsController < AdminController
def create def create
@domain = ReservedDomain.new(reserved_params) @domain = ReservedDomain.new(reserved_domain_params)
if @domain.save if @domain.save
flash[:notice] = I18n.t('domain_added') flash[:notice] = I18n.t('domain_added')
@ -35,7 +35,7 @@ class Admin::ReservedDomainsController < AdminController
def update def update
if @domain.update(reserved_params) if @domain.update(reserved_domain_params)
flash[:notice] = I18n.t('domain_updated') flash[:notice] = I18n.t('domain_updated')
else else
flash.now[:alert] = I18n.t('failed_to_update_domain') flash.now[:alert] = I18n.t('failed_to_update_domain')
@ -58,7 +58,7 @@ class Admin::ReservedDomainsController < AdminController
private private
def reserved_params def reserved_domain_params
params.require(:reserved_domain).permit(:name, :password) params.require(:reserved_domain).permit(:name, :password)
end end

View file

@ -1,5 +1,6 @@
class BlockedDomain < ActiveRecord::Base class BlockedDomain < ActiveRecord::Base
include Versions include Versions
validates :name, domain_name: true, uniqueness: true
after_initialize -> { self.names = [] if names.nil? } after_initialize -> { self.names = [] if names.nil? }
end end

View file

@ -3,6 +3,9 @@ class ReservedDomain < ActiveRecord::Base
before_save :fill_empty_passwords before_save :fill_empty_passwords
before_save :generate_data before_save :generate_data
before_destroy :remove_data before_destroy :remove_data
validates :name, domain_name: true, uniqueness: true
class << self class << self

View file

@ -16,7 +16,7 @@
.col-md-4.control-label .col-md-4.control-label
= f.label :password = f.label :password
.col-md-7 .col-md-7
= f.text_field(:password, class: 'form-control') = f.text_field(:password, placeholder: t(:optional), class: 'form-control')
.row .row
.col-md-8.text-right .col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-primary') = button_tag(t(:save), class: 'btn btn-primary')

View file

@ -932,4 +932,5 @@ en:
expiration_remind_subject: 'The %{name} domain has expired' expiration_remind_subject: 'The %{name} domain has expired'
add_reserved_domain: 'Add domain to reserved list' add_reserved_domain: 'Add domain to reserved list'
add_blocked_domain: 'Add domain to blocked list' add_blocked_domain: 'Add domain to blocked list'
edit_pw: 'Edit Pw' edit_pw: 'Edit Pw'
optional: 'Optional'