Updated

app/controllers/admin / domains_controller.rb

B
78 lines of codes
11 methods
4.4 complexity/method
1 churn
48.26 complexity
37 duplications
class Admin::DomainsController < Admin::AdminController
  1. Admin::DomainsController assumes too much for instance variable '@domain'
  2. Admin::DomainsController has no descriptive comment
before_action :require_sysadmin before_action :fetch_domains before_action :build_domain, only: %i[new create] before_action :find_domain, only: %i[edit update destroy] def index respond_to do |format| format.html end end def new respond_to do |format| format.html end end def create
  1. Similar code found in 2 nodes Locations: 0 1
if @domain.save redirect_to admin_domains_url, notice: :domain_created else respond_to do |format| format.html { render :new } end end end def edit respond_to do |format| format.html end end def update
  1. Similar code found in 2 nodes Locations: 0 1
if @domain.update(domain_params) redirect_to admin_domains_url, notice: :domain_updated else respond_to do |format| format.html { render :edit } end end end def destroy if @domain.destroy redirect_to admin_domains_url, notice: :domain_deleted else redirect_to admin_domains_url, alert: :domain_not_deleted end end private def fetch_domains @domains = Domain.by_name.paginate(page: params[:page], per_page: 25) end def find_domain @domain = Domain.find(params[:id]) end def build_domain @domain = Domain.new(domain_params) end def domain_params if params.key?(:domain) params.require(:domain).permit(*domain_attributes) else {} end end def domain_attributes %i[name strip_characters strip_extension aliased_domain] end end