Validates_format_of before type_cast?


#1

Often I need to do a one-off validation before Rails has had a chance to
convert. For example, a date. Is there a general mechanism to cause
validations to run on the raw input or do I have to resort to:

private
def validate
unless attributes_before_type_cast[‘date_of_loss’] =~
/^(\d+(-|/)){2}\d{4}/
errors.add(‘date_of_loss’, ‘use the form: mm/dd/yyyy’)
end
end

Thanks

(BTW: I know there is a date validation plugin)

View this message in context:
http://www.nabble.com/validates_format_of-before-type_cast--t1295244.html#a3448544
Sent from the RubyOnRails Users forum at Nabble.com.