Class: Decidim::Consultations::Admin::CreateConsultation
- Inherits:
-
Decidim::Command
- Object
- Decidim::Command
- Decidim::Consultations::Admin::CreateConsultation
- Defined in:
- app/commands/decidim/consultations/admin/create_consultation.rb
Overview
A command with all the business logic when creating a new participatory consultation in the system.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateConsultation
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ CreateConsultation
Public: Initializes the command.
form - A form object with the params.
12 13 14 |
# File 'app/commands/decidim/consultations/admin/create_consultation.rb', line 12 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form wasn’t valid and we couldn’t proceed.
Returns nothing.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/commands/decidim/consultations/admin/create_consultation.rb', line 22 def call return broadcast(:invalid) if form.invalid? consultation = create_consultation if consultation.persisted? broadcast(:ok, consultation) else form.errors.add(:banner_image, consultation.errors[:banner_image]) if consultation.errors.include? :banner_image form.errors.add(:introductory_image, consultation.errors[:introductory_image]) if consultation.errors.include? :introductory_image broadcast(:invalid) end end |