first_class_dates

Installation

first_class_dates is Rails plugin. Install as normal with a plugin:

> script/plugin install http://opensource.thinkrelevance.com/svn/plugins/first_class_dates/tags/stable/first_class_dates

Dependencies

first_class_dates's tests rely on test/spec

> sudo gem install test-spec

Overview

When it comes to Rails validation, dates are second-class citizens. Invalid dates (such as Feb 30) are allowed by Rails helpers, but instead of triggering validation errors they raise an ActiveRecord::MultiparameterAssignmentError.

I (Stu) think that such invalid dates should be treated as validation errors, for consistency with, well, every other kind of validation in Rails.

If you include this plugin, invalid dates will be reported as validation errors instead.

There are no configuration options because I haven't needed them yet.

Usage

Simply add the plugin. That's it.

Other Approaches

Shinya Kasatani's Validates Multiparameter Assignments plugin lets you turn on a similar validation per model class.