Class: Admin::AdminUsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/admin_users_controller.rb

Defined Under Namespace

Classes: Collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adminObject (readonly)

Returns the value of attribute admin.



7
8
9
# File 'app/controllers/admin/admin_users_controller.rb', line 7

def admin
  @admin
end

Instance Method Details

#archiveObject



53
54
55
56
57
# File 'app/controllers/admin/admin_users_controller.rb', line 53

def archive
  Admin::User.where(id: params[:id]).where.not(id: current_admin.id).each(&:archive!)

  redirect_back(fallback_location: admin_admin_users_path, status: :see_other)
end

#archivedObject



15
16
17
18
19
# File 'app/controllers/admin/admin_users_controller.rb', line 15

def archived
  collection = Collection.new.with_params(params).apply(Admin::User.archived.strict_loading)

  render locals: { collection: }
end

#createObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/admin/admin_users_controller.rb', line 35

def create
  admin = Admin::User.new(admin_user_params)

  if admin.save
    redirect_to admin_admin_user_path(admin)
  else
    render :new, locals: { admin: }, status: :unprocessable_content
  end
end

#destroyObject



65
66
67
68
69
# File 'app/controllers/admin/admin_users_controller.rb', line 65

def destroy
  admin.destroy

  redirect_to admin_admin_users_path
end

#editObject



31
32
33
# File 'app/controllers/admin/admin_users_controller.rb', line 31

def edit
  render :edit, locals: { admin: }
end

#indexObject



9
10
11
12
13
# File 'app/controllers/admin/admin_users_controller.rb', line 9

def index
  collection = Collection.new.with_params(params).apply(Admin::User.strict_loading)

  render locals: { collection: }
end

#newObject



25
26
27
28
29
# File 'app/controllers/admin/admin_users_controller.rb', line 25

def new
  @admin = Admin::User.new

  render :new, locals: { admin: }
end

#restoreObject



59
60
61
62
63
# File 'app/controllers/admin/admin_users_controller.rb', line 59

def restore
  Admin::User.archived.where(id: params[:id]).each(&:restore!)

  redirect_back(fallback_location: admin_admin_users_path, status: :see_other)
end

#showObject



21
22
23
# File 'app/controllers/admin/admin_users_controller.rb', line 21

def show
  render :show, locals: { admin: }
end

#updateObject



45
46
47
48
49
50
51
# File 'app/controllers/admin/admin_users_controller.rb', line 45

def update
  if admin.update(admin_user_params)
    redirect_to action: :show
  else
    render :edit, locals: { admin: }, status: :unprocessable_content
  end
end