Class: Decidim::Demographics::Admin::SettingsController

Inherits:
ApplicationController show all
Defined in:
decidim-demographics/app/controllers/decidim/demographics/admin/settings_controller.rb

Instance Method Summary collapse

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from NeedsSnippets

#snippets

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#showObject



7
8
9
10
11
# File 'decidim-demographics/app/controllers/decidim/demographics/admin/settings_controller.rb', line 7

def show
  enforce_permission_to(:update, :demographics)

  @form = form(Admin::DemographicsSettingsForm).from_model(demographic)
end

#updateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'decidim-demographics/app/controllers/decidim/demographics/admin/settings_controller.rb', line 13

def update
  enforce_permission_to(:update, :demographics)

  @form = form(Admin::DemographicsSettingsForm).from_params(params)

  Admin::UpdateDemographicsSettings.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("update.success", scope: "decidim.demographics.admin.settings")
      redirect_to decidim_admin_demographics.settings_path
    end

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