Class: Decidim::Consultations::Admin::QuestionConfigurationController

Inherits:
ApplicationController show all
Includes:
QuestionAdmin
Defined in:
decidim-consultations/app/controllers/decidim/consultations/admin/question_configuration_controller.rb

Instance Method Summary collapse

Methods included from RegistersPermissions

register_permissions

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 NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#editObject


11
12
13
14
15
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/question_configuration_controller.rb', line 11

def edit
  enforce_permission_to :configure, :question, question: current_question
  @form = question_form.from_model(current_question, current_consultation: current_consultation)
  render layout: "decidim/admin/question"
end

#updateObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/question_configuration_controller.rb', line 17

def update
  enforce_permission_to :configure, :question, question: current_question

  @form = question_form
          .from_params(params, question_id: current_question.id, current_consultation: current_consultation)

  UpdateQuestionConfiguration.call(current_question, @form) do
    on(:ok) do |question|
      flash[:notice] = I18n.t("questions.update.success", scope: "decidim.admin")
      redirect_to edit_question_configuration_path(question)
    end

    on(:invalid) do |_question, error|
      flash[:error] = I18n.t("questions.update.error", scope: "decidim.admin")
      flash[:error] << " (#{error})" if error
      render :edit, layout: "decidim/admin/question"
    end
  end
end