app/models/answer.rb
# implement the method where the validation logic must reside
implement the method where the validation logic must reside
implement the method where the validation logic must reside
def validate(record)
      return unless record.errors.empty?
      if (record.user_type == 'ScaleAnswer' && record.int_value.nil?) ||
          (record.user_type == 'ListAnswer' && record.value.nil?)
        record.errors[:base] << I18n.t('answer.model.select_one_option')
      elsif (record.user_type == 'RadioAnswer')
        if record.question.other.nil?
          if record.value.nil?
            record.errors[:base] << I18n.t('answer.model.select_one_option')
          end
        else
          if record.value.nil?
            if (record.text_value.nil? || record.text_value.empty?)
              record.errors[:base] << I18n.t('answer.model.select_one_option')
            end
          end
        end
      elsif record.user_type == 'FreeTextAnswer' && (record.text_value.nil? || record.text_value.empty?)
        record.errors[:base] << I18n.t('answer.model.write_an_answer')
      elsif record.user_type == 'FreeTextAnswer' && (record.text_value.mb_chars.length < 10)
        record.errors[:base] << I18n.t('answer.model.answer_too_short')
      elsif record.user_type == 'CheckboxAnswer'
unless record.value.nil?
  if (record.text_value.nil? || record.text_value.empty?)
    record.errors[:base] << I18n.t('answer.model.write_an_answer')
    return
  end
end
        if (record.values.nil? || record.values.empty?) && record.value.nil?
          record.errors[:base] << I18n.t('answer.model.select_at_least_one')
        end
      end
    end
def validate ( record ) return unless record . errors . empty? if ( record . user_type == 'ScaleAnswer' && record . int_value . nil? ) || ( record . user_type == 'ListAnswer' && record . value . nil? ) record . errors [ :base ] << I18n . t ( 'answer.model.select_one_option' ) elsif ( record . user_type == 'RadioAnswer' ) if record . question . other . nil? if record . value . nil? record . errors [ :base ] << I18n . t ( 'answer.model.select_one_option' ) end else if record . value . nil? if ( record . text_value . nil? || record . text_value . empty? ) record . errors [ :base ] << I18n . t ( 'answer.model.select_one_option' ) end end end elsif record . user_type == 'FreeTextAnswer' && ( record . text_value . nil? || record . text_value . empty? ) record . errors [ :base ] << I18n . t ( 'answer.model.write_an_answer' ) elsif record . user_type == 'FreeTextAnswer' && ( record . text_value . mb_chars . length < 10 ) record . errors [ :base ] << I18n . t ( 'answer.model.answer_too_short' ) elsif record . user_type == 'CheckboxAnswer' if ( record . values . nil? || record . values . empty? ) && record . value . nil? record . errors [ :base ] << I18n . t ( 'answer.model.select_at_least_one' ) end end end
implement the method where the validation logic must reside
implement the method where the validation logic must reside
# Select other... #        Commented due to be not understandable for normal people #         #        unless record.value.nil? #          if (record.text_value.nil? || record.text_value.empty?) #            record.errors[:base] << I18n.t('answer.model.write_an_answer') #            return #          end #        end
record
<not_specific>