Class: Decidim::ActionDelegator::Admin::PonderationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Paginable, NeedsPermission
Defined in:
app/controllers/decidim/action_delegator/admin/ponderations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/decidim/action_delegator/admin/ponderations_controller.rb', line 24

def create
  enforce_permission_to :create, :ponderation

  @form = PonderationForm.from_params(params).with_context(setting: current_setting)

  CreatePonderation.call(@form) do
    on(:ok) do
      notice = I18n.t("ponderations.create.success", scope: "decidim.action_delegator.admin")
      redirect_to setting_ponderations_path(current_setting), notice: notice
    end

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

#destroyObject



65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/decidim/action_delegator/admin/ponderations_controller.rb', line 65

def destroy
  enforce_permission_to :destroy, :ponderation, resource: ponderation

  if ponderation.destroy
    notice = I18n.t("ponderations.destroy.success", scope: "decidim.action_delegator.admin")
    redirect_to setting_ponderations_path(current_setting), notice: notice
  else
    error = I18n.t("ponderations.destroy.error", scope: "decidim.action_delegator.admin")
    redirect_to setting_ponderations_path(current_setting), flash: { error: error }
  end
end

#editObject



42
43
44
45
46
# File 'app/controllers/decidim/action_delegator/admin/ponderations_controller.rb', line 42

def edit
  enforce_permission_to :update, :ponderation

  @form = form(PonderationForm).from_model(ponderation)
end

#indexObject



14
15
16
# File 'app/controllers/decidim/action_delegator/admin/ponderations_controller.rb', line 14

def index
  enforce_permission_to :index, :ponderation
end

#newObject



18
19
20
21
22
# File 'app/controllers/decidim/action_delegator/admin/ponderations_controller.rb', line 18

def new
  enforce_permission_to :create, :ponderation

  @form = form(PonderationForm).instance
end

#updateObject



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

def update
  enforce_permission_to :update, :ponderation

  @form = PonderationForm.from_params(params).with_context(setting: current_setting)
  UpdatePonderation.call(@form, ponderation) do
    on(:ok) do
      notice = I18n.t("ponderations.update.success", scope: "decidim.action_delegator.admin")
      redirect_to setting_ponderations_path(current_setting), notice: notice
    end

    on(:invalid) do |_error|
      flash.now[:error] = I18n.t("ponderations.update.error", scope: "decidim.action_delegator.admin")
      render :edit
    end
  end
end