1class Admin::DomainsController < Admin::AdminController  | 
         |
            2 before_action :require_sysadmin  | 
         |
            3 before_action :fetch_domains  | 
         |
            4 before_action :build_domain, only: %i[new create]  | 
         |
            5 before_action :find_domain, only: %i[edit update destroy]  | 
         |
            7 def index  | 
         |
            8 respond_to do |format|  | 
         |
             9      format.html
 | 
         |
            10 end  | 
         |
            11 end  | 
         |
            13 def new  | 
         |
            14 respond_to do |format|  | 
         |
            15      format.html
 | 
         |
            16 end  | 
         |
            17 end  | 
         |
            19 def create  | 
         |
            20 if @domain.save  | 
         |
            21 redirect_to admin_domains_url, notice: :domain_created  | 
         |
            22 else  | 
         |
            23 respond_to do |format|  | 
         |
            24 format.html { render :new }  | 
         |
            25 end  | 
         |
            26 end  | 
         |
            27 end  | 
         |
            29 def edit  | 
         |
            30 respond_to do |format|  | 
         |
            31      format.html
 | 
         |
            32 end  | 
         |
            33 end  | 
         |
            35 def update  | 
         |
            36 if @domain.update(domain_params)  | 
         |
            37 redirect_to admin_domains_url, notice: :domain_updated  | 
         |
            38 else  | 
         |
            39 respond_to do |format|  | 
         |
            40 format.html { render :edit }  | 
         |
            41 end  | 
         |
            42 end  | 
         |
            43 end  | 
         |
            45 def destroy  | 
         |
            46 if @domain.destroy  | 
         |
            47 redirect_to admin_domains_url, notice: :domain_deleted  | 
         |
            48 else  | 
         |
            49 redirect_to admin_domains_url, alert: :domain_not_deleted  | 
         |
            50 end  | 
         |
            51 end  | 
         |
            53  private
 | 
         |
            55 def fetch_domains  | 
         |
            56 @domains = Domain.by_name.paginate(page: params[:page], per_page: 25)  | 
         |
            57 end  | 
         |
            59 def find_domain  | 
         |
            60 @domain = Domain.find(params[:id])  | 
         |
            61 end  | 
         |
            63 def build_domain  | 
         |
            64 @domain = Domain.new(domain_params)  | 
         |
            65 end  | 
         |
            67 def domain_params  | 
         |
            68 if params.key?(:domain)  | 
         |
            69 params.require(:domain).permit(*domain_attributes)  | 
         |
            70 else  | 
         |
            71      {}
 | 
         |
            72 end  | 
         |
            73 end  | 
         |
            75 def domain_attributes  | 
         |
            76 %i[name strip_characters strip_extension aliased_domain]  | 
         |
            77 end  | 
         |
            78end  |