Class: Decidim::Surveys::SurveyAnswerForm

Inherits:
Form
  • Object
show all
Includes:
TranslationsHelper
Defined in:
app/forms/decidim/surveys/survey_answer_form.rb

Overview

This class holds a Form to update survey unswers from Decidim’s public page

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#questionObject



23
24
25
# File 'app/forms/decidim/surveys/survey_answer_form.rb', line 23

def question
  @question ||= Decidim::Surveys::SurveyQuestion.find(question_id)
end

Instance Method Details

#label(idx) ⇒ Object



27
28
29
30
31
32
# File 'app/forms/decidim/surveys/survey_answer_form.rb', line 27

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.



37
38
39
40
41
42
43
44
# File 'app/forms/decidim/surveys/survey_answer_form.rb', line 37

def map_model(model)
  self.question_id = model.decidim_survey_question_id
  self.question = model.question

  self.choices = model.choices.map do |choice|
    SurveyAnswerChoiceForm.from_model(choice)
  end
end

#selected_choicesObject



46
47
48
# File 'app/forms/decidim/surveys/survey_answer_form.rb', line 46

def selected_choices
  choices.select(&:body)
end