Forum: Ruby on Rails validates_format_of before type_cast?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Steve R. (Guest)
on 2006-03-17 03:16
(Received via mailing list)
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-t...
Sent from the RubyOnRails Users forum at Nabble.com.
This topic is locked and can not be replied to.