Class: Decidim::Elections::VotesController
- Inherits:
-
ApplicationController
- Object
- Components::BaseController
- ApplicationController
- Decidim::Elections::VotesController
- Includes:
- UsesVotesBooth, FormFactory
- Defined in:
- app/controllers/decidim/elections/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
-
#cast ⇒ Object
Casts the votes that have been saved in the session and redirects to the receipt page.
-
#confirm ⇒ Object
Shows the confirmation page with the votes that will be cast.
-
#show ⇒ Object
Show the voting form for the given question.
-
#update ⇒ Object
Saves the vote for the current question and redirect to the next question.
Methods included from UsesVotesBooth
Instance Method Details
#cast ⇒ Object
Casts the votes that have been saved in the session and redirects to the receipt page
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/decidim/elections/votes_controller.rb', line 33 def cast (:create, :vote, election:) CastVotes.call(election, votes_buffer, voter_uid) do on(:ok) do votes_buffer.clear session[:voter_uid] = voter_uid session_attributes.clear redirect_to receipt_election_votes_path(election), notice: t("votes.cast.success", scope: "decidim.elections") end on(:invalid) do redirect_to confirm_election_votes_path(election), alert: I18n.t("votes.cast.invalid", scope: "decidim.elections") end end end |
#confirm ⇒ Object
Shows the confirmation page with the votes that will be cast
28 29 30 |
# File 'app/controllers/decidim/elections/votes_controller.rb', line 28 def confirm (:create, :vote, election:) end |
#show ⇒ Object
Show the voting form for the given question
15 16 17 |
# File 'app/controllers/decidim/elections/votes_controller.rb', line 15 def show (:create, :vote, election:) end |
#update ⇒ Object
Saves the vote for the current question and redirect to the next question
20 21 22 23 24 25 |
# File 'app/controllers/decidim/elections/votes_controller.rb', line 20 def update (:create, :vote, election:) votes_buffer[question.id.to_s] = params.dig(:response, question.id.to_s) redirect_to next_vote_step_path end |