Class: Decidim::Templates::Admin::CreateQuestionnaireTemplate

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-templates/app/commands/decidim/templates/admin/create_questionnaire_template.rb

Overview

Creates a QuestionnaireTemplate.

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateQuestionnaireTemplate

Initializes the command.

form - The source for this QuestionnaireTemplate.


11
12
13
# File 'decidim-templates/app/commands/decidim/templates/admin/create_questionnaire_template.rb', line 11

def initialize(form)
  @form = form
end

Instance Method Details

#callObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'decidim-templates/app/commands/decidim/templates/admin/create_questionnaire_template.rb', line 15

def call
  return broadcast(:invalid) unless @form.valid?

  @template = Decidim.traceability.create!(
    Template,
    @form.current_user,
    name: @form.name,
    description: @form.description,
    organization: @form.current_organization
  )

  @questionnaire = Decidim::Forms::Questionnaire.create!(questionnaire_for: @template)
  @template.update!(templatable: @questionnaire)

  broadcast(:ok, @template)
end