Class: Decidim::Solutions::CreateSolution

Inherits:
Command
  • Object
show all
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

Methods included from CommandUtils

#challenge_id, #parsed_attribute

Methods included from Challenges

decidim_version, version

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

#callObject

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 process_attachments?
      build_attachments
      create_attachments
    end
  end

  broadcast(:ok, solution)
end