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

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

Instance Method Summary collapse

Instance Method Details

#showObject



7
8
9
10
11
# File '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 '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_content
    end
  end
end