Class: Decidim::Consultations::Admin::ResponsesController

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

Overview

Controller that manages responses for a question

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/responses_controller.rb', line 22

def create
  enforce_permission_to :create, :response
  @form = response_form.from_params(params, current_question: current_question)

  CreateResponse.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("responses.create.success", scope: "decidim.admin")
      redirect_to responses_path(current_question)
    end

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

#destroyObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/decidim/consultations/admin/responses_controller.rb', line 61

def destroy
  enforce_permission_to :destroy, :response, response: current_response

  current_response.destroy
  if current_response.valid?
    flash[:notice] = I18n.t("responses.destroy.success", scope: "decidim.admin")
    redirect_to responses_path(current_question)
  else
    flash.now[:alert] = I18n.t("responses.destroy.error", scope: "decidim.admin")
    render :edit
  end
end

#editObject



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

def edit
  enforce_permission_to :update, :response, response: current_response
  @form = response_form.from_model(current_response, current_question: current_question)
end

#indexObject



13
14
15
# File 'app/controllers/decidim/consultations/admin/responses_controller.rb', line 13

def index
  enforce_permission_to :read, :response
end

#newObject



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

def new
  enforce_permission_to :create, :response
  @form = response_form.instance
end

#updateObject



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

def update
  enforce_permission_to :update, :response, response: current_response

  @form = response_form.from_params(params, current_question: current_question)
  UpdateResponse.call(current_response, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("responses.update.success", scope: "decidim.admin")
      redirect_to responses_path(current_question)
    end

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