So a lot of Rails apps (mine included) have multiple validations on a
single attribute. For example: on the password field, validating that
it is (a) not blank, (b) matches the confirmation, (c) is at least X
characters long, and (d) contains at least 1 alpha and at least 1
numeric character.
The problem is: if that field is blank, the default errors shows all
four. That's a little intimidating to novice web users.
Is there a recommended way to somehow set the validations in an order
of precedence and only show the first failed validation for a given
field?
BTW, I know I can just roll my own validations or muck with the errors
object on the model, but I'm looking to see if there is a simpler,
recommended way to do this that I've overlooked.
So a lot of Rails apps (mine included) have multiple validations on a
single attribute. For example: on the password field, validating that
it is (a) not blank, (b) matches the confirmation, (c) is at least X
characters long, and (d) contains at least 1 alpha and at least 1
numeric character.
The problem is: if that field is blank, the default errors shows all
four. That's a little intimidating to novice web users.
Is there a recommended way to somehow set the validations in an order
of precedence and only show the first failed validation for a given
field?
BTW, I know I can just roll my own validations or muck with the errors
object on the model, but I'm looking to see if there is a simpler,
recommended way to do this that I've overlooked.
Thoughts anyone?
You could always set :allow_blank => true on the validations (except the validate_presence_of one of course). That way they won't appear unless the user has entered something.
Although, one could make an argument that if they screw up you should let them know what you expect so they don't have to do it again. I *hate* when a form tells me it's too short, then it tells me it doesn't have a capital letter, then it tells me it doesn't have a number, then a symbol, then it complains that I can't use 74 as it was the year I was born, also 'PH' isn't allowed, etc. etc. etc...
And while I'm complaining, for the love of whatever it is you love, don't make me enter a phone number using your pre-conceived notions about formatting. Just take my 10 digits and format them yourself!