Class: Decidim::Initiatives::Admin::InitiativesSettingsController

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

Overview

Controller used to manage the initiatives settings for the current organization.

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permissions_context

Instance Method Details

#editObject

GET /admin/initiatives_settings/edit



14
15
16
17
# File 'app/controllers/decidim/initiatives/admin/initiatives_settings_controller.rb', line 14

def edit
  enforce_permission_to :update, :initiatives_settings, initiatives_settings: current_initiatives_settings
  @form = initiatives_settings_form.from_model(current_initiatives_settings)
end

#updateObject

PUT /admin/initiatives_settings



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

def update
  enforce_permission_to :update, :initiatives_settings, initiatives_settings: current_initiatives_settings

  @form = initiatives_settings_form
          .from_params(params, initiatives_settings: current_initiatives_settings)

  UpdateInitiativesSettings.call(@form, current_initiatives_settings) do
    on(:ok) do
      flash[:notice] = I18n.t("initiatives_settings.update.success", scope: "decidim.admin")
      redirect_to edit_initiatives_setting_path
    end

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