internetee-registry/app/controllers/admin/domains_controller.rb
2014-09-25 17:04:16 +03:00

39 lines
889 B
Ruby

class Admin::DomainsController < AdminController
before_action :set_domain, only: [:show, :edit, :update]
def index
@q = Domain.search(params[:q])
@domains = @q.result.page(params[:page])
end
def show
@domain.all_dependencies_valid?
end
def edit
@domain.domain_statuses.build if @domain.domain_statuses.empty?
end
def update
if @domain.update(domain_params)
flash[:notice] = I18n.t('shared.domain_updated')
redirect_to [:admin, @domain]
else
@domain.domain_statuses.build if @domain.domain_statuses.empty?
flash.now[:alert] = I18n.t('shared.failed_to_update_domain')
render 'edit'
end
end
private
def set_domain
@domain = Domain.find(params[:id])
end
def domain_params
params.require(:domain).permit(
domain_statuses_attributes: [:id, :value, :description, :_destroy]
)
end
end