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

#admin_userObject (readonly)

Returns the value of attribute admin_user.



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

def admin_user
  @admin_user
end

Instance Method Details

#archiveObject



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

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

  redirect_back_or_to(admin_admin_users_path, status: :see_other)
end

#archivedObject



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

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

  render locals: { collection: }
end

#createObject



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

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

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

#destroyObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/admin/admin_users_controller.rb', line 66

def destroy
  return redirect_back_or_to(admin_admin_users_path, status: :see_other) if admin_user == current_admin

  if admin_user.archived?
    admin_user.destroy!

    redirect_to admin_admin_users_path
  else
    admin_user.archive!

    redirect_back_or_to(admin_admin_user_path(admin_user), status: :see_other)
  end
end

#editObject



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

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

#indexObject



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

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

  render locals: { collection: }
end

#newObject



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

def new
  @admin_user = Admin::User.new

  render locals: { admin_user: }
end

#restoreObject



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

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

  redirect_back_or_to(admin_admin_users_path, status: :see_other)
end

#showObject



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

def show
  render locals: { admin_user: }
end

#updateObject



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

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