Class: Decidim::System::AdminsController

Inherits:
ApplicationController show all
Defined in:
decidim-system/app/controllers/decidim/system/admins_controller.rb

Overview

Controller that allows managing all the Admins.

Instance Method Summary collapse

Methods included from HttpCachingDisabler

#disable_http_caching

Instance Method Details

#createObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'decidim-system/app/controllers/decidim/system/admins_controller.rb', line 16

def create
  @form = form(AdminForm).from_params(params)

  CreateAdmin.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("admins.create.success", scope: "decidim.system")
      redirect_to admins_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("admins.create.error", scope: "decidim.system")
      render :new
    end
  end
end

#destroyObject


58
59
60
61
62
63
# File 'decidim-system/app/controllers/decidim/system/admins_controller.rb', line 58

def destroy
  @admin = Admin.find(params[:id]).destroy!
  flash[:notice] = I18n.t("admins.destroy.success", scope: "decidim.system")

  redirect_to admins_path
end

#editObject


32
33
34
35
# File 'decidim-system/app/controllers/decidim/system/admins_controller.rb', line 32

def edit
  @admin = Admin.find(params[:id])
  @form = form(AdminForm).from_model(@admin)
end

#indexObject


8
9
10
# File 'decidim-system/app/controllers/decidim/system/admins_controller.rb', line 8

def index
  @admins = Admin.all
end

#newObject


12
13
14
# File 'decidim-system/app/controllers/decidim/system/admins_controller.rb', line 12

def new
  @form = form(AdminForm).instance
end

#showObject


54
55
56
# File 'decidim-system/app/controllers/decidim/system/admins_controller.rb', line 54

def show
  @admin = Admin.find(params[:id])
end

#updateObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'decidim-system/app/controllers/decidim/system/admins_controller.rb', line 37

def update
  @admin = Admin.find(params[:id])
  @form = form(AdminForm).from_params(params)

  UpdateAdmin.call(@admin, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("admins.update.success", scope: "decidim.system")
      redirect_to admins_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("admins.update.error", scope: "decidim.system")
      render :edit
    end
  end
end