Alex D
Alex D

Reputation: 30445

How to query what attributes on an ActiveRecord model are validated?

Is there a way to query which attributes on an ActiveRecord model are validated? Say I have a model like this:

class Person < ActiveRecord::Base validates_presence_of :name validates_numericality_of :age end

I would like something like this:

Person.validations => [:name, :age]

Upvotes: 0

Views: 108

Answers (1)

apneadiving
apneadiving

Reputation: 115511

This does the trick:

Person.validators.map {|v| v.attributes if v.attributes }.flatten

Upvotes: 3

Related Questions