Class: Decidim::Assemblies::Admin::AssembliesController

Inherits:
Decidim::Admin::ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/assemblies/admin/assemblies_controller.rb

Overview

Controller that allows managing assemblies.

Instance Method Summary collapse

Instance Method Details

#copyObject



74
75
76
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 74

def copy
  authorize! :create, Decidim::Assembly
end

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 22

def create
  authorize! :new, Decidim::Assembly
  @form = form(AssemblyForm).from_params(params)

  CreateAssembly.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("assemblies.create.success", scope: "decidim.admin")
      redirect_to assemblies_path
    end

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

#destroyObject



65
66
67
68
69
70
71
72
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 65

def destroy
  authorize! :destroy, current_assembly
  current_assembly.destroy!

  flash[:notice] = I18n.t("assemblies.destroy.success", scope: "decidim.admin")

  redirect_to assemblies_path
end

#editObject



39
40
41
42
43
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 39

def edit
  authorize! :update, current_assembly
  @form = form(AssemblyForm).from_model(current_assembly)
  render layout: "decidim/admin/assembly"
end

#indexObject



12
13
14
15
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 12

def index
  authorize! :index, Decidim::Assembly
  @assemblies = collection
end

#newObject



17
18
19
20
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 17

def new
  authorize! :new, Decidim::Assembly
  @form = form(AssemblyForm).instance
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/decidim/assemblies/admin/assemblies_controller.rb', line 45

def update
  authorize! :update, current_assembly
  @form = form(AssemblyForm).from_params(
    assembly_params,
    assembly_id: current_assembly.id
  )

  UpdateAssembly.call(current_assembly, @form) do
    on(:ok) do |assembly|
      flash[:notice] = I18n.t("assemblies.update.success", scope: "decidim.admin")
      redirect_to edit_assembly_path(assembly)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("assemblies.update.error", scope: "decidim.admin")
      render :edit, layout: "decidim/admin/assembly"
    end
  end
end