instance method
validators_on
Ruby on Rails 4.1.16
Since v3.0.20Signature
validators_on(*attributes)
List all validators that are being used to validate a specific attribute.
class Person include ActiveModel::Validations attr_accessor :name , :age validates_presence_of :name validates_inclusion_of :age, in: 0..99 end Person.validators_on(:name) # => [ # #<ActiveModel::Validations::PresenceValidator:0x007fe604914e60 @attributes=[:name], @options={}>, # ]
Parameters
-
attributesrest
Source
# File activemodel/lib/active_model/validations.rb, line 235
def validators_on(*attributes)
attributes.flat_map do |attribute|
_validators[attribute.to_sym]
end
end
Defined in activemodel/lib/active_model/validations.rb line 235
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Validations::ClassMethods