NEWS:

Uncategorized 25 Jun 2005 10:13 pm

Validating a date

I can’t find a built-in rails method to validate a given date. E.g., that February 30th should not be allowed for a date field. However, rails does throw an exception which you can catch and add your own error.

begin
  success = @person.update_attributes(@params[:person])
rescue ActiveRecord::MultiparameterAssignmentErrors
  @person.errors.add(:birthdate, ' entered is not a valid date')
end

Somebody let me know if I’m missing something here. It seems that since this exception is thrown that the framework would have the validation available.

Comments are closed.