Class: Decidim::Elections::Admin::CreateElection
- Inherits:
-
Command
- Object
- Command
- Decidim::Elections::Admin::CreateElection
- Includes:
- GalleryMethods
- Defined in:
- app/commands/decidim/elections/admin/create_election.rb
Overview
This command is executed when the user creates an Election from the admin panel.
Instance Method Summary collapse
-
#call ⇒ Object
Creates the election if valid.
-
#initialize(form) ⇒ CreateElection
constructor
A new instance of CreateElection.
Constructor Details
#initialize(form) ⇒ CreateElection
Returns a new instance of CreateElection.
11 12 13 |
# File 'app/commands/decidim/elections/admin/create_election.rb', line 11 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Creates the election if valid.
Broadcasts :ok if successful, :invalid otherwise.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/commands/decidim/elections/admin/create_election.rb', line 18 def call return broadcast(:invalid) if form.invalid? if process_gallery? build_gallery return broadcast(:invalid) if gallery_invalid? end transaction do create_election! create_gallery if process_gallery? end broadcast(:ok, election) end |