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

#createObject



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

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_entity
  end
end

#destroyObject



51
52
53
54
55
# File 'app/controllers/admin/admin_users_controller.rb', line 51

def destroy
  admin.destroy

  redirect_to admin_admin_users_path
end

#editObject



29
30
31
# File 'app/controllers/admin/admin_users_controller.rb', line 29

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

#indexObject



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

def index
  collection = Collection.new.with_params(params).apply(Admin::User.strict_loading)
  table      = Koi::IndexTableComponent.new(collection:, partial: "admin")

  respond_to do |format|
    format.turbo_stream { render(table) } if self_referred?
    format.html { render :index, locals: { table:, collection: } }
  end
end

#newObject



23
24
25
26
27
# File 'app/controllers/admin/admin_users_controller.rb', line 23

def new
  @admin = Admin::User.new

  render :new, locals: { admin: }
end

#showObject



19
20
21
# File 'app/controllers/admin/admin_users_controller.rb', line 19

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

#updateObject



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

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