awkward silence |

Archive for June 25th, 2005

Jun/05

25

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.

No tags

Theme Design by devolux.nh2.me