Class: Decidim::Forms::AnswerQuestionnaire
- Inherits:
-
Command
- Object
- Command
- Decidim::Forms::AnswerQuestionnaire
- Includes:
- MultipleAttachmentsMethods
- Defined in:
- app/commands/decidim/forms/answer_questionnaire.rb
Overview
This command is executed when the user answers a Questionnaire.
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#questionnaire ⇒ Object
readonly
Returns the value of attribute questionnaire.
Instance Method Summary collapse
-
#call ⇒ Object
Answers a questionnaire if it is valid.
-
#initialize(form, questionnaire) ⇒ AnswerQuestionnaire
constructor
Initializes a AnswerQuestionnaire Command.
Constructor Details
#initialize(form, 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.
14 15 16 17 |
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 14 def initialize(form, questionnaire) @form = form @questionnaire = questionnaire end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
37 38 39 |
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 37 def form @form end |
#questionnaire ⇒ Object (readonly)
Returns the value of attribute questionnaire.
37 38 39 |
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 37 def questionnaire @questionnaire end |
Instance Method Details
#call ⇒ Object
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 34 35 |
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 22 def call return broadcast(:invalid) if @form.invalid? || user_already_answered? with_events do answer_questionnaire end if @errors broadcast(:invalid) else broadcast(:ok) end end |