Class: Decidim::ActionDelegator::Admin::SettingsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Filterable, Paginable
Defined in:
app/controllers/decidim/action_delegator/admin/settings_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/settings_controller.rb', line 24

def create
  enforce_permission_to :create, :setting

  @form = form(SettingForm).from_params(params)

  CreateSetting.call(@form, copy_from_setting) do
    on(:ok) do
      notice = I18n.t("settings.create.success", scope: "decidim.action_delegator.admin")
      redirect_to decidim_admin_action_delegator.settings_path, notice: notice
    end

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

#destroyObject



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

def destroy
  enforce_permission_to :destroy, :setting, resource: setting

  if setting.destroy
    flash[:notice] = I18n.t("settings.destroy.success", scope: "decidim.action_delegator.admin")
  else
    flash[:error] = I18n.t("settings.destroy.error", scope: "decidim.action_delegator.admin")
  end

  redirect_to settings_path
end

#editObject



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

def edit
  enforce_permission_to :update, :setting

  @form = form(SettingForm).from_model(setting)
end

#indexObject



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

def index
  enforce_permission_to :index, :setting
end

#newObject



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

def new
  enforce_permission_to :create, :setting

  @form = form(SettingForm).instance
end

#updateObject



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

def update
  enforce_permission_to :update, :setting

  @form = form(SettingForm).from_params(params)

  UpdateSetting.call(@form, setting, copy_from_setting) do
    on(:ok) do
      notice = I18n.t("settings.update.success", scope: "decidim.action_delegator.admin")
      redirect_to decidim_admin_action_delegator.settings_path, notice: notice
    end

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