Sha256: 4c30acbe0109b8a1749a825615d68c369e2ccf88b04f68ceed8cf65e366ed7a9
Contents?: true
Size: 503 Bytes
Versions: 1
Compression:
Stored size: 503 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 1 of these fields must be present: #{attr_names.to_sentence(last_word_connector: ', or ')}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activemodel-validators-1.0.0 | lib/activemodel-validators/at_least_one_present_validator.rb |