Class: Decidim::Consultations::Admin::QuestionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/decidim/consultations/admin/questions_controller.rb', line 22

def create
  enforce_permission_to :create, :question
  @form = question_form.from_params(params, current_consultation: current_consultation)

  CreateQuestion.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("questions.create.success", scope: "decidim.admin")
      redirect_to consultation_questions_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("questions.create.error", scope: "decidim.admin")
      render :new, layout: "decidim/admin/consultation"
    end
  end
end

#destroyObject



64
65
66
67
68
69
70
71
# File 'app/controllers/decidim/consultations/admin/questions_controller.rb', line 64

def destroy
  enforce_permission_to :destroy, :question, question: current_question
  current_question.destroy!

  flash[:notice] = I18n.t("questions.destroy.success", scope: "decidim.admin")

  redirect_to consultation_questions_path(current_consultation)
end

#editObject



39
40
41
42
43
# File 'app/controllers/decidim/consultations/admin/questions_controller.rb', line 39

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

#indexObject



10
11
12
13
14
# File 'app/controllers/decidim/consultations/admin/questions_controller.rb', line 10

def index
  enforce_permission_to :read, :question
  @questions = collection
  render layout: "decidim/admin/consultation"
end

#newObject



16
17
18
19
20
# File 'app/controllers/decidim/consultations/admin/questions_controller.rb', line 16

def new
  enforce_permission_to :create, :question
  @form = question_form.instance
  render layout: "decidim/admin/consultation"
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/decidim/consultations/admin/questions_controller.rb', line 45

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

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

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

    on(:invalid) do
      flash.now[:alert] = I18n.t("questions.update.error", scope: "decidim.admin")
      render :edit, layout: "decidim/admin/question"
    end
  end
end