Class: Decidim::Debates::Admin::DebatesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/debates/admin/debates_controller.rb

Overview

This controller allows an admin to manage debates from a Participatory Space

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  enforce_permission_to :create, :debate

  @form = form(Decidim::Debates::Admin::DebateForm).from_params(params, current_component:)

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

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

#destroyObject



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

def destroy
  enforce_permission_to(:delete, :debate, debate:)

  debate.destroy!

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

  redirect_to debates_path
end

#editObject



40
41
42
43
44
# File 'app/controllers/decidim/debates/admin/debates_controller.rb', line 40

def edit
  enforce_permission_to(:update, :debate, debate:)

  @form = form(Decidim::Debates::Admin::DebateForm).from_model(debate)
end

#indexObject



12
13
14
# File 'app/controllers/decidim/debates/admin/debates_controller.rb', line 12

def index
  enforce_permission_to :read, :debate
end

#newObject



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

def new
  enforce_permission_to :create, :debate

  @form = form(Decidim::Debates::Admin::DebateForm).instance
end

#updateObject



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

def update
  enforce_permission_to(:update, :debate, debate:)

  @form = form(Decidim::Debates::Admin::DebateForm).from_params(params, current_component:)

  UpdateDebate.call(@form, debate) do
    on(:ok) do
      flash[:notice] = I18n.t("debates.update.success", scope: "decidim.debates.admin")
      redirect_to debates_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("debates.update.invalid", scope: "decidim.debates.admin")
      render action: "edit"
    end
  end
end