Class: Decidim::Meetings::AnswerForm

Inherits:
Form
  • Object
show all
Includes:
TranslationsHelper
Defined in:
app/forms/decidim/meetings/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

Instance Attribute Details

#questionObject



19
20
21
# File 'app/forms/decidim/meetings/answer_form.rb', line 19

def question
  @question ||= Decidim::Meetings::Question.find(question_id)
end

Instance Method Details

#answerObject



23
24
25
# File 'app/forms/decidim/meetings/answer_form.rb', line 23

def answer
  @answer ||= Decidim::Meetings::Answer.find_by(decidim_user_id: current_user.id, decidim_question_id: question_id) if current_user
end

#labelObject



27
28
29
30
31
# File 'app/forms/decidim/meetings/answer_form.rb', line 27

def label
  base = translated_attribute(question.body)
  base += " (#{max_choices_label})" if question.max_choices
  base
end

#map_model(model) ⇒ Object

Public: Map the correct fields.

Returns nothing.



36
37
38
39
40
41
42
43
# File 'app/forms/decidim/meetings/answer_form.rb', line 36

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_choicesObject



45
46
47
# File 'app/forms/decidim/meetings/answer_form.rb', line 45

def selected_choices
  choices.select(&:answer_option_id)
end