I am using Ruby on Rails 3 and I would like to retrieve validating field names. That is, I defined some validation for a class and I would like to retrieve what fields (their names) are candidate for validation on submitting a form.
I need that because I would like to “play” with class error attributes (<name_class>.errors).
How can I do?
You can access your model’s
validatorsmethod. This will return an array of validators on your model.For example, if you had this:
Then you could access the validators like this: