Class: Decidim::Elections::Voter::CastVote
- Inherits:
-
Command
- Object
- Command
- Decidim::Elections::Voter::CastVote
- Defined in:
- app/commands/decidim/elections/voter/cast_vote.rb
Overview
This command allows the user to store and cast their vote.
Instance Method Summary collapse
-
#call ⇒ Object
Store and cast the vote.
-
#initialize(form) ⇒ CastVote
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ CastVote
Public: Initializes the command.
form - A form with necessary info to cast a vote.
11 12 13 |
# File 'app/commands/decidim/elections/voter/cast_vote.rb', line 11 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Store and cast the vote
Broadcasts :ok if successful, :invalid otherwise
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/commands/decidim/elections/voter/cast_vote.rb', line 18 def call return broadcast(:invalid) if form.invalid? transaction do cast_vote end broadcast(:ok, vote) rescue StandardError => e broadcast(:invalid, e.) end |