validators_on

validators_on(*attributes)
Instance Public methods

List all validators that are being used to validate a specific attribute.

1
2
3
4
5
6
7
8
9
10
11
12
13
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={}>,
#    ]
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.