Class: Decidim::Elections::TrusteeZone::TrusteesController

Inherits:
ApplicationController show all
Includes:
FormFactory
Defined in:
app/controllers/decidim/elections/trustee_zone/trustees_controller.rb

Overview

Exposes the trustee zone for trustee users

Instance Method Summary collapse

Instance Method Details

#showObject



10
11
12
13
14
# File 'app/controllers/decidim/elections/trustee_zone/trustees_controller.rb', line 10

def show
  enforce_permission_to :view, :trustee, trustee: trustee

  trustee.name ||= current_user.name
end

#updateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/decidim/elections/trustee_zone/trustees_controller.rb', line 16

def update
  enforce_permission_to :update, :trustee, trustee: trustee

  form = form(TrusteeForm).from_params(params, trustee: trustee)

  UpdateTrustee.call(form) do
    on(:ok) do
      flash[:notice] = I18n.t("trustees.update.success", scope: "decidim.elections.trustee_zone")
    end

    on(:invalid) do
      flash[:alert] = form.errors.full_messages.to_sentence
    end
  end

  redirect_to trustee_path
end