Skip to content

Instantly share code, notes, and snippets.

View ankit8898's full-sized avatar

Ankit gupta ankit8898

View GitHub Profile
@ankit8898
ankit8898 / extensions.rb
Created September 4, 2012 13:25
Custom date validation to prevent the save of default date in Rails Activerecord with validates_with
Place this file in your config/initializers
class CheckDate < ActiveModel::Validator
#Sat Jan 01 00:00:00 UTC 2000 is the default date that rails store
def validate(record)
if record.start_time == "Sat Jan 01 00:00:00 UTC 2000".to_date
record.errors[:base] << "This is a invalid date"
end
end