Class: Decidim::Surveys::CreateSurvey

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/surveys/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.



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

def initialize(component)
  @component = component
end

Instance Method Details

#callObject



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

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

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