Class: Decidim::Surveys::Admin::UpdateSurvey

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

Overview

This command is executed when the user changes a Survey from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(form, survey) ⇒ UpdateSurvey

Initializes a UpdateSurvey Command.

form - The form from which to get the data. survey - The current instance of the survey to be updated.



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

def initialize(form, survey)
  @form = form
  @survey = survey
end

Instance Method Details

#callObject

Updates the survey if valid.

Broadcasts :ok if successful, :invalid otherwise.



21
22
23
24
25
26
27
28
29
30
# File 'decidim-surveys/app/commands/decidim/surveys/admin/update_survey.rb', line 21

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

  Survey.transaction do
    update_survey_questions if @survey.questions_editable?
    update_survey
  end

  broadcast(:ok)
end