I’ve noticed that validates_format_of will return invalid if the field
is nil.
Question 1) How should we declare a validation that will validate it
with a regex if it is set, but, if the field is not set, just move on
Question 2) Why is it done this way? The other validators are only
invoked if the field is set . If you want to declare the field
mandatory, you add a validates_presence_of. This seems to me to be the
best design - why does validates_format_of break this?
Am I making a mistake here? If so, someone please clue me in.
Likewise, if my questions are unclear, please let me know, and I’ll try
to clarify.
lstrecv wrote:
I’ve noticed that validates_format_of will return invalid if the field
is nil.
Question 1) How should we declare a validation that will validate it
with a regex if it is set, but, if the field is not set, just move on
Question 2) Why is it done this way? The other validators are only
invoked if the field is set . If you want to declare the field
mandatory, you add a validates_presence_of. This seems to me to be the
best design - why does validates_format_of break this?
is nil.
mandatory, you add a validates_presence_of. This
seems to me to be the
best design - why does validates_format_of break
this?
I argued elsewhere that the only validation that
should fail on nil is the validates_presence_of. That
makes this concept orthogonal to all other
validations. Results in less code most of the time to.
The argument was not accepted, so we’ve branched our
rails tree, and it will have this behavior. I’ll be
posting a big patch somewhere soon.
It was mentioned that this will be changed in a post
1.0 release.
Shawn
Yahoo! DSL ? Something to write home about.
Just $16.99/mo. or less. dsl.yahoo.com
is nil.
mandatory, you add a validates_presence_of. This
seems to me to be the
best design - why does validates_format_of break
this?
I argued elsewhere that the only validation that
should fail on nil is the validates_presence_of. That
makes this concept orthogonal to all other
validations. Results in less code most of the time to.
The argument was not accepted, so we’ve branched our
rails tree, and it will have this behavior. I’ll be
posting a big patch somewhere soon.
It was mentioned that this will be changed in a post
1.0 release.
Shawn
Yahoo! DSL � Something to write home about.
Just $16.99/mo. or less. dsl.yahoo.com