Module: ActiveModel::Validations::HelperMethods

Defined in:
lib/activemodel/extra_validations/presence_of_at_least_one_of.rb

Overview

Methods to be automatically included on every ActiveModel instance

Instance Method Summary collapse

Instance Method Details

#validate_presence_of_at_least_one_of(*attribute_names) ⇒ Object

Validates whether at least one of the specified attributes is present.

class BillingDetails < ActiveRecord::Base
  validate_presence_of_at_least_one_of :credit_card, :debit_card
end

Configuration options:

  • :message - Specifies a custom error message (default is: “is not included in the list”).

See ActiveModel::Validations#validates for more information



58
59
60
# File 'lib/activemodel/extra_validations/presence_of_at_least_one_of.rb', line 58

def validate_presence_of_at_least_one_of(*attribute_names)
  validates_with PresenceOfAtLeastOneOfValidator, _merge_attributes(attribute_names)
end