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

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

Instance Method Summary collapse

Instance Method Details

#editObject



11
12
13
14
15
# File '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 '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