Class: Decidim::Elections::VotesController

Inherits:
ApplicationController show all
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

Methods included from UsesVotesBooth

#receipt

Instance Method Details

#castObject

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
  enforce_permission_to(: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

#confirmObject

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
  enforce_permission_to(:create, :vote, election:)
end

#showObject

Show the voting form for the given question



15
16
17
# File 'app/controllers/decidim/elections/votes_controller.rb', line 15

def show
  enforce_permission_to(:create, :vote, election:)
end

#updateObject

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
  enforce_permission_to(:create, :vote, election:)

  votes_buffer[question.id.to_s] = params.dig(:response, question.id.to_s)
  redirect_to next_vote_step_path
end