Class: Decidim::Meetings::AnswerForm
- Inherits:
 - 
      Form
      
        
- Object
 - Form
 - Decidim::Meetings::AnswerForm
 
 
- 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
- #answer ⇒ Object
 - #label ⇒ Object
 - 
  
    
      #map_model(model)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Public: Map the correct fields.
 - #selected_choices ⇒ Object
 
Instance Attribute Details
Instance Method Details
#answer ⇒ Object
      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  | 
  
#label ⇒ Object
      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_choices ⇒ Object
      45 46 47  | 
    
      # File 'app/forms/decidim/meetings/answer_form.rb', line 45 def selected_choices choices.select(&:answer_option_id) end  |