Class: Decidim::Surveys::Admin::CreateSurvey

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/surveys/admin/create_survey.rb

Overview

Command that gets called whenever a component’s survey has to be created. It usually happens as a callback when the component itself is created.

Instance Method Summary collapse

Constructor Details

#initialize(component) ⇒ CreateSurvey

Returns a new instance of CreateSurvey.



9
10
11
# File 'app/commands/decidim/surveys/admin/create_survey.rb', line 9

def initialize(component)
  @component = component
end

Instance Method Details

#callObject



13
14
15
16
17
# File 'app/commands/decidim/surveys/admin/create_survey.rb', line 13

def call
  @survey = Survey.new(component: @component, questionnaire: Decidim::Forms::Questionnaire.new)

  @survey.save ? broadcast(:ok, @survey) : broadcast(:invalid)
end