Class: Decidim::Elections::Admin::AnswersController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Elections::Admin::AnswersController
- Defined in:
- app/controllers/decidim/elections/admin/answers_controller.rb
Overview
This controller allows the create or update answers for a question.
Instance Method Summary collapse
- #change_selected(selected) ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #select ⇒ Object
- #unselect ⇒ Object
- #update ⇒ Object
Instance Method Details
#change_selected(selected) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 67 def change_selected(selected) (:select, :answer, election:, question:) UpdateAnswerSelection.call(answer, selected) do on(:ok) do flash[:notice] = if selected I18n.t("answers.select.success", scope: "decidim.elections.admin") else I18n.t("answers.unselect.success", scope: "decidim.elections.admin") end end on(:invalid) do flash.now[:alert] = if selected I18n.t("answers.select.invalid", scope: "decidim.elections.admin") else I18n.t("answers.unselect.invalid", scope: "decidim.elections.admin") end end end redirect_to election_question_answers_path(election, question) end |
#create ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 20 def create (:update, :answer, election:, question:) @form = form(AnswerForm).from_params(params, election:, question:) CreateAnswer.call(@form) do on(:ok) do flash[:notice] = I18n.t("answers.create.success", scope: "decidim.elections.admin") redirect_to election_question_answers_path(election, question) end on(:invalid) do flash.now[:alert] = I18n.t("answers.create.invalid", scope: "decidim.elections.admin") render action: "new" end end end |
#destroy ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 91 def destroy (:update, :answer, election:, question:) DestroyAnswer.call(answer, current_user) do on(:ok) do flash[:notice] = I18n.t("answers.destroy.success", scope: "decidim.elections.admin") end on(:invalid) do flash.now[:alert] = I18n.t("answers.destroy.invalid", scope: "decidim.elections.admin") end end redirect_to election_question_answers_path(election, question) end |
#edit ⇒ Object
37 38 39 40 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 37 def edit (:update, :answer, election:, question:) @form = form(AnswerForm).from_model(answer) end |
#index ⇒ Object
11 12 13 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 11 def index flash.now[:alert] = I18n.t("answers.index.invalid_max_selections", scope: "decidim.elections.admin", missing_answers:) if missing_answers.positive? end |
#new ⇒ Object
15 16 17 18 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 15 def new (:update, :answer, election:, question:) @form = form(AnswerForm).instance end |
#select ⇒ Object
59 60 61 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 59 def select change_selected(true) end |
#unselect ⇒ Object
63 64 65 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 63 def unselect change_selected(false) end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/decidim/elections/admin/answers_controller.rb', line 42 def update (:update, :answer, election:, question:) @form = form(AnswerForm).from_params(params, election:, question:) UpdateAnswer.call(@form, answer) do on(:ok) do flash[:notice] = I18n.t("answers.update.success", scope: "decidim.elections.admin") redirect_to election_question_answers_path(election, question) end on(:invalid) do flash.now[:alert] = I18n.t("answers.update.invalid", scope: "decidim.elections.admin") render action: "edit" end end end |