mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 10:49:39 +02:00
Status form update #2623
This commit is contained in:
parent
bed27ce940
commit
9b9e1a3068
3 changed files with 31 additions and 32 deletions
|
@ -16,9 +16,9 @@ class Admin::DomainsController < AdminController
|
|||
end
|
||||
|
||||
def update
|
||||
add_prefix_to_statuses
|
||||
dp = add_prefix_to_statuses
|
||||
|
||||
if @domain.update(domain_params)
|
||||
if @domain.update(dp)
|
||||
flash[:notice] = I18n.t('domain_updated')
|
||||
redirect_to [:admin, @domain]
|
||||
else
|
||||
|
@ -53,21 +53,24 @@ class Admin::DomainsController < AdminController
|
|||
end
|
||||
|
||||
def domain_params
|
||||
params.require(:domain).permit(
|
||||
domain_statuses_attributes: [:id, :value, :description, :_destroy]
|
||||
)
|
||||
if params[:domain]
|
||||
params.require(:domain).permit({ statuses: [] })
|
||||
else
|
||||
{statuses: []}
|
||||
end
|
||||
end
|
||||
|
||||
def build_associations
|
||||
@domain.domain_statuses.build if @domain.domain_statuses.empty?
|
||||
@server_statuses = @domain.domain_statuses.select(&:server_status?)
|
||||
@server_statuses << @domain.domain_statuses.build if @server_statuses.empty?
|
||||
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
@server_statuses = [nil] if @server_statuses.empty?
|
||||
end
|
||||
|
||||
def add_prefix_to_statuses
|
||||
domain_params[:domain_statuses_attributes].each do |_k, hash|
|
||||
hash[:value] = hash[:value].prepend('server') if hash[:value].present?
|
||||
end
|
||||
dp = domain_params
|
||||
dp[:statuses] = domain_params[:statuses].map { |x| x.prepend('server') if x.present? }
|
||||
dp[:statuses].reject! { |x| x.blank? }
|
||||
dp
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue