Class: Decidim::Solutions::CreateSolution
- Inherits:
-
Command
- Object
- Command
- Decidim::Solutions::CreateSolution
- Includes:
- Challenges, CommandUtils, MultipleAttachmentsMethods
- Defined in:
- app/commands/decidim/solutions/create_solution.rb
Overview
A command with all the business logic when a user creates a new solution.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateSolution
constructor
Public: Initializes the command.
Methods included from CommandUtils
#challenge_id, #parsed_attribute
Methods included from Challenges
Constructor Details
#initialize(form) ⇒ CreateSolution
Public: Initializes the command.
form - A form object with the params.
14 15 16 17 |
# File 'app/commands/decidim/solutions/create_solution.rb', line 14 def initialize(form) super() @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid, together with the solution.
-
:invalid if the form wasn’t valid and we couldn’t proceed.
Returns nothing.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/commands/decidim/solutions/create_solution.rb', line 25 def call return broadcast(:invalid) if form.invalid? transaction do create_solution! if end end broadcast(:ok, solution) end |