Sha256: 58433e4985631c095fd3c17d7383e266a893e052c7d419fbd9effd698726996d
Contents?: true
Size: 895 Bytes
Versions: 6
Compression:
Stored size: 895 Bytes
Contents
# frozen_string_literal: true module Decidim module Surveys # This class holds a Form to update survey unswers from Decidim's public page class SurveyAnswerForm < Decidim::Form attribute :question_id, String attribute :body, String validates :body, presence: true, if: -> { question.mandatory? } validate :body_not_blank, if: -> { question.mandatory? } def question @question ||= survey.questions.find(question_id) end # Public: Map the correct fields. # # Returns nothing. def map_model(model) self.question_id = model.decidim_survey_question_id end private def survey @survey ||= Survey.where(feature: current_feature).first end def body_not_blank return if body.nil? errors.add("body", :blank) if body.all?(&:blank?) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems