Class: Decidim::Surveys::AnswerSurvey

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

Overview

This command is executed when the user answers a Survey.

Instance Method Summary collapse

Constructor Details

#initialize(form, current_user, survey) ⇒ AnswerSurvey

Initializes a AnswerSurvey Command.

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



11
12
13
14
15
# File 'decidim-surveys/app/commands/decidim/surveys/answer_survey.rb', line 11

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

Instance Method Details

#callObject

Answers a survey if it is valid

Broadcasts :ok if successful, :invalid otherwise.



20
21
22
23
24
25
# File 'decidim-surveys/app/commands/decidim/surveys/answer_survey.rb', line 20

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

  answer_survey
  broadcast(:ok)
end