Sha256: 03bb7b23920d7b26b43096a4f1fcef283873a7097dc287899274e75608e0c606
Contents?: true
Size: 549 Bytes
Versions: 5
Compression:
Stored size: 549 Bytes
Contents
module ActiveModel module Validations class AtLeastOnePresentValidator < ActiveModel::Validator def validate(record) attr_names = options[:at_least_one_of] #puts %(attr_names=#{attr_names.inspect}) unless attr_names.map {|attr_name| record[attr_name]}.any?(&:present?) record.errors.add :base, options[:message] || :at_least_one_field_must_be_present, attr_names_list: attr_names.to_sentence(two_words_connector: ' or ', last_word_connector: ', or ') end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems