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