class AtLeastOneOfValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/at_least_one_of_validator.rb, line 6
def validate_each(record, attribute, value)
  attributes = options[:in] + [attribute]
  if attributes.all? { |name| record.try(name).nil? }
    record.errors.add(attribute, "is required because at least one of #{attributes.to_sentence} are required")
  end
end