Skip to content

Instantly share code, notes, and snippets.

@martinos
Created September 11, 2010 00:36
Show Gist options
  • Select an option

  • Save martinos/574614 to your computer and use it in GitHub Desktop.

Select an option

Save martinos/574614 to your computer and use it in GitHub Desktop.
module ActiveRecord
module Validations
module ClassMethods
def validates_as_date(*attr_names)
configuration = {
:message => 'is invalid date format',
:allow_nil => true }
# configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
debugger
validates_each(attr_names, configuration) do |record, attr_name, value|
debugger
date = Date.strptime(value, '%Y-%m-%d') rescue nil
if date.nil?
record.errors.add(attr_name, configuration[:message])
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment