Class: Decidim::Surveys::Admin::CreateSurvey
- Inherits:
-
Command
- Object
- Command
- Decidim::Surveys::Admin::CreateSurvey
- 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 Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(component, form) ⇒ CreateSurvey
constructor
A new instance of CreateSurvey.
Constructor Details
#initialize(component, form) ⇒ CreateSurvey
Returns a new instance of CreateSurvey.
9 10 11 12 |
# File 'app/commands/decidim/surveys/admin/create_survey.rb', line 9 def initialize(component, form) @component = component @form = form end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
14 15 16 |
# File 'app/commands/decidim/surveys/admin/create_survey.rb', line 14 def form @form end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/commands/decidim/surveys/admin/create_survey.rb', line 16 def call return broadcast(:invalid) if form.invalid? @survey = Survey.new( component: @component, questionnaire: Decidim::Forms::Questionnaire.new( title: form.title, description: form.description, tos: form.tos ) ) @survey.save ? broadcast(:ok, @survey) : broadcast(:invalid) end |