Sha256: 5a71de70c8cd6b7d00f2140a1a17e1592fe379f52663eadccf42c204c9534204
Contents?: true
Size: 871 Bytes
Versions: 48
Compression:
Stored size: 871 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.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
48 entries across 48 versions & 2 rubygems