Adam Meehan

Results 36 comments of Adam Meehan

I think the best comparison to make is with `validates_numericality_of` where if you have an integer column and assign a junk string, the error of `not a number` is returned...

Though, admittedly in the case of numericality it casts junk as 0 (grrr), so the column doesn't return nil. Basically I consider blank, when there has been no attempt to...

In your case, what value is the column being filled with to trigger the validation?

Couple of things. The validation should be written as `validates_datetime :column_name, format: /yyyy[\/-]mm[\/-]dd\shh\:nn\:ss/, allow_blank: true` But specifically, the `format` option is not meant to be a regexp but a Timeliness...

put the Timeliness line in an initializer.

Ah sorry I should have been more explicit. After adding that format the validation becomes simply this `validates_datetime :column_name, allow_blank: true`

Also for safety move the `Timeliness.add_formats` call outside the setup do block.

That is not really supported directly in the validation. It is really necessary to be so restrictive on the format? How is the datetime being captured, web form?

ah ok. you can never rely on client side validation alone, but restricting the format would be easier.

What version of Rails/ActiveRecord are you using?