Class: Decidim::Meetings::ResponseForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Meetings::ResponseForm
- Includes:
- TranslationsHelper
- Defined in:
- app/forms/decidim/meetings/response_form.rb
Overview
This class holds a Form to save the questionnaire responses from Decidim’s public page
Instance Attribute Summary collapse
Instance Method Summary collapse
- #label ⇒ Object
-
#map_model(model) ⇒ Object
Public: Map the correct fields.
- #response ⇒ Object
- #selected_choices ⇒ Object
Instance Attribute Details
#question ⇒ Object
19 20 21 |
# File 'app/forms/decidim/meetings/response_form.rb', line 19 def question @question ||= Decidim::Meetings::Question.find(question_id) end |
Instance Method Details
#label ⇒ Object
27 28 29 30 31 |
# File 'app/forms/decidim/meetings/response_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/response_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| ResponseChoiceForm.from_model(choice) end end |
#response ⇒ Object
23 24 25 |
# File 'app/forms/decidim/meetings/response_form.rb', line 23 def response @response ||= Decidim::Meetings::Response.find_by(decidim_user_id: current_user.id, decidim_question_id: question_id) if current_user end |
#selected_choices ⇒ Object
45 46 47 |
# File 'app/forms/decidim/meetings/response_form.rb', line 45 def selected_choices choices.select(&:response_option_id) end |