Class: Decidim::Elections::PerQuestionVotesController
- Inherits:
-
ApplicationController
- Object
- Components::BaseController
- ApplicationController
- Decidim::Elections::PerQuestionVotesController
- Includes:
- UsesVotesBooth, FormFactory
- Defined in:
- app/controllers/decidim/elections/per_question_votes_controller.rb
Overview
Provides access to election resources so that users can participate Election.where(component: current_component).published.lections.
Instance Method Summary collapse
-
#show ⇒ Object
Show the voting form for the given question Responds to HTML (render the form) and JSON (check question status for polling).
-
#update ⇒ Object
Saves the vote for the current question and redirect to the next question.
-
#waiting ⇒ Object
If the election is per-question, this action will be called to show the waiting page while the user waits for the next question to be available.
Methods included from UsesVotesBooth
Instance Method Details
#show ⇒ Object
Show the voting form for the given question Responds to HTML (render the form) and JSON (check question status for polling)
24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/decidim/elections/per_question_votes_controller.rb', line 24 def show (:create, :vote, election:) respond_to do |format| format.html format.json do render json: question_status_response end end end |
#update ⇒ Object
Saves the vote for the current question and redirect to the next question
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/decidim/elections/per_question_votes_controller.rb', line 36 def update (:create, :vote, election:) response_ids = params.dig(:response, question.id.to_s) requeue_following_questions votes_buffer[question.id.to_s] = response_ids CastVotes.call(election, { question.id.to_s => response_ids }, voter_uid) do on(:ok) do session[:voter_uid] = voter_uid flash[:notice] = t("votes.cast.success", scope: "decidim.elections") redirect_to(**next_vote_step_action) end on(:invalid) do action = { action: :show, id: question } action = next_vote_step_action unless question.voting_enabled? flash[:alert] = t("votes.cast.invalid", scope: "decidim.elections") redirect_to(**action) end end end |
#waiting ⇒ Object
If the election is per-question, this action will be called to show the waiting page while the user waits for the next question to be available. If the election is not per-question, this action will redirect to the next question
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/decidim/elections/per_question_votes_controller.rb', line 62 def waiting (:create, :vote, election:) redirect_action = waiting_for_next_question? ? nil : next_vote_step_action respond_to do |format| format.html do redirect_to(**redirect_action) if redirect_action.present? end format.json do render json: { url: redirect_action ? url_for(**redirect_action) : nil } end end end |