Class: Decidim::Forms::AnswerForm
- Inherits:
-
Decidim::Form
- Object
- Decidim::Form
- Decidim::Forms::AnswerForm
- Includes:
- TranslationsHelper
- Defined in:
- app/forms/decidim/forms/answer_form.rb
Overview
This class holds a Form to save the questionnaire answers from Decidim’s public page
Instance Attribute Summary collapse
Instance Method Summary collapse
- #label(idx) ⇒ Object
-
#map_model(model) ⇒ Object
Public: Map the correct fields.
- #selected_choices ⇒ Object
Instance Attribute Details
#question ⇒ Object
25 26 27 |
# File 'app/forms/decidim/forms/answer_form.rb', line 25 def question @question ||= Decidim::Forms::Question.find(question_id) end |
Instance Method Details
#label(idx) ⇒ Object
29 30 31 32 33 34 |
# File 'app/forms/decidim/forms/answer_form.rb', line 29 def label(idx) base = "#{idx + 1}. #{translated_attribute(question.body)}" base += " #{mandatory_label}" if question.mandatory? base += " (#{max_choices_label})" if question.max_choices base end |
#map_model(model) ⇒ Object
Public: Map the correct fields.
Returns nothing.
39 40 41 42 43 44 45 46 |
# File 'app/forms/decidim/forms/answer_form.rb', line 39 def map_model(model) self.question_id = model.decidim_question_id self.question = model.question self.choices = model.choices.map do |choice| AnswerChoiceForm.from_model(choice) end end |
#selected_choices ⇒ Object
48 49 50 |
# File 'app/forms/decidim/forms/answer_form.rb', line 48 def selected_choices choices.select(&:body) end |