@@ -62,7 +62,10 @@ def validate_each(record, attr_name, value)
62
62
end
63
63
64
64
unless is_time? ( option_value ) && value . to_i . send ( CHECKS [ option ] , option_value . to_i )
65
- record . errors . add ( attr_name , option , options . merge ( :value => original_value , :date => original_option_value ) )
65
+ record . errors . add ( attr_name , option , options . merge (
66
+ :value => original_value ,
67
+ :date => ( I18n . localize ( original_option_value ) rescue original_option_value )
68
+ ) )
66
69
end
67
70
end
68
71
end
@@ -73,5 +76,23 @@ def is_time?(object)
73
76
object . is_a? ( Time ) || ( defined? ( Date ) and object . is_a? ( Date ) ) || ( defined? ( ActiveSupport ::TimeWithZone ) and object . is_a? ( ActiveSupport ::TimeWithZone ) )
74
77
end
75
78
end
79
+
80
+ module HelperMethods
81
+ # Validates whether the value of the specified attribute is a validate Date
82
+ #
83
+ # class Person < ActiveRecord::Base
84
+ # validates_date_of :payment_date, :after => :packaging_date
85
+ # validates_date_of :expiration_date, :before => Proc.new { Time.now }
86
+ # end
87
+ #
88
+ # Configuration options:
89
+ # * <tt>:after</tt> - check that a Date is after the specified one.
90
+ # * <tt>:before</tt> - check that a Date is before the specified one.
91
+ # * <tt>:after_or_equal_to</tt> - check that a Date is after or equal to the specified one.
92
+ # * <tt>:before_or_equal_to</tt> - check that a Date is before or equal to the specified one.
93
+ def validates_date_of ( *attr_names )
94
+ validates_with DateValidator , _merge_attributes ( attr_names )
95
+ end
96
+ end
76
97
end
77
98
end
0 commit comments