Class: Decidim::Initiatives::Admin::AnswersController

Inherits:
ApplicationController show all
Includes:
NeedsInitiative
Defined in:
decidim-initiatives/app/controllers/decidim/initiatives/admin/answers_controller.rb

Overview

Controller used to manage the initiatives answers

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permissions_context

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#editObject

GET /admin/initiatives/:id/answer/edit


14
15
16
17
18
19
20
21
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/answers_controller.rb', line 14

def edit
  enforce_permission_to :answer, :initiative, initiative: current_initiative
  @form = form(Decidim::Initiatives::Admin::InitiativeAnswerForm)
          .from_model(
            current_initiative,
            initiative: current_initiative
          )
end

#updateObject

PUT /admin/initiatives/:id/answer


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'decidim-initiatives/app/controllers/decidim/initiatives/admin/answers_controller.rb', line 24

def update
  enforce_permission_to :answer, :initiative, initiative: current_initiative

  @form = form(Decidim::Initiatives::Admin::InitiativeAnswerForm)
          .from_params(params, initiative: current_initiative)

  UpdateInitiativeAnswer.call(current_initiative, @form, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("initiatives.update.success", scope: "decidim.initiatives.admin")
      redirect_to initiatives_path
    end

    on(:invalid) do
      flash[:alert] = I18n.t("initiatives.update.error", scope: "decidim.initiatives.admin")
      redirect_to edit_initiative_answer_path
    end
  end
end