Class: Decidim::Forms::AnswerQuestionnaire

Inherits:
Rectify::Command
  • Object
show all
Includes:
MultipleAttachmentsMethods
Defined in:
decidim-forms/app/commands/decidim/forms/answer_questionnaire.rb

Overview

This command is executed when the user answers a Questionnaire.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, current_user, questionnaire) ⇒ AnswerQuestionnaire

Initializes a AnswerQuestionnaire Command.

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


13
14
15
16
17
# File 'decidim-forms/app/commands/decidim/forms/answer_questionnaire.rb', line 13

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

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form


35
36
37
# File 'decidim-forms/app/commands/decidim/forms/answer_questionnaire.rb', line 35

def form
  @form
end

Instance Method Details

#callObject

Answers a questionnaire if it is valid

Broadcasts :ok if successful, :invalid otherwise.


22
23
24
25
26
27
28
29
30
31
32
33
# File 'decidim-forms/app/commands/decidim/forms/answer_questionnaire.rb', line 22

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

  answer_questionnaire

  if @errors
    reset_form_attachments
    broadcast(:invalid)
  else
    broadcast(:ok)
  end
end