app/forms/decidim/surveys/survey_answer_form.rb in decidim-surveys-0.11.1 vs app/forms/decidim/surveys/survey_answer_form.rb in decidim-surveys-0.11.2

- old
+ new

@@ -16,12 +16,14 @@ validate :max_choices, if: -> { question.max_choices } validate :all_choices, if: -> { question.question_type == "sorting" } delegate :mandatory_body?, :mandatory_choices?, to: :question + attr_writer :question + def question - @question ||= survey.questions.find(question_id) + @question ||= Decidim::Surveys::SurveyQuestion.find(question_id) end def label(idx) base = "#{idx + 1}. #{translated_attribute(question.body)}" base += " #{mandatory_label}" if question.mandatory? @@ -32,10 +34,11 @@ # Public: Map the correct fields. # # Returns nothing. 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 @@ -43,13 +46,9 @@ def selected_choices choices.select(&:body) end private - - def survey - @survey ||= Survey.find_by(component: current_component) - end def max_choices errors.add(:choices, :too_many) if selected_choices.size > question.max_choices end