Method: ActiveModel::Validations::ClassMethods#validators_on
- Defined in:
- lib/active_model/validations.rb
#validators_on(*attributes) ⇒ Object
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={}>,
# ]
234 235 236 237 238 |
# File 'lib/active_model/validations.rb', line 234 def validators_on(*attributes) attributes.flat_map do |attribute| _validators[attribute.to_sym] end end |