doc tweaks

This commit is contained in:
Adam Meehan
2009-02-09 18:12:08 +11:00
parent 12aa78271e
commit 1181b725d0

View File

@@ -51,34 +51,31 @@ validation method
end
The list of validation methods available are as follows:
* validates_date - validate value as date
* validates_time - validate value as time only i.e. '12:20pm'
* validates_datetime - validate value as a full date and time
* validates_date - validate value as date
* validates_time - validate value as time only i.e. '12:20pm'
* validates_datetime - validate value as a full date and time
The validation methods take the usual options plus some specific ones to restrict
the valid range of dates or times allowed
Temporal options (or restrictions):
Temporal options (or restrictions):
:before - Attribute must be before this value to be valid
:on_or_before - Attribute must be equal to or before this value to be valid
:after - Attribute must be after this value to be valid
:on_or_after - Attribute must be equal to or after this value to be valid
:between - Attribute must be between the values to be valid
:between - Attribute must be between the values to be valid. Takes an array of two values or a range
Regular validation options:
Regular validation options:
:allow_nil - Allow a nil value to be valid
:allow_blank - Allows a nil or empty string value to be valid
:if - Execute validation when :if evaluates true
:unless - Execute validation when :unless evaluates false
Special options:
Special options:
:with_time - Validate a date attribute value combined with a time value against any temporal restrictions
:with_date - Validate a time attribute value combined with a date value against any temporal restrictions
Message options: - Use these to override the default error messages
Message options: - Use these to override the default error messages
:invalid_date_message
:invalid_time_message
:invalid_datetime_message
@@ -88,17 +85,17 @@ the valid range of dates or times allowed
:on_or_after_message
:between_message
The temporal restrictions can take 4 different value types:
* String value
* Date, Time, or DateTime object value
* Proc or lambda object
* A symbol matching the method name in the model
* Between option takes an array of two values or a range
The temporal restrictions, with_date and with_time can take 4 different value types:
* String value
* Date, Time, or DateTime object value
* Proc or lambda object which may take an optional parameter being the record object
* A symbol matching the method name in the model
When an attribute value is compared to temporal restrictions, they are compared as
the same type as the validation method type. So using validates_date means all
values are compared as dates.
values are compared as dates. This s except in the case of with_time and with_date
options which effectively force the value to validated as a datetime against the
temporal options.
== EXAMPLES:
@@ -112,6 +109,8 @@ values are compared as dates.
validates_datetime :appointment_date, :before => Proc.new { 1.week.from_now }
validates_datetime :appointment_date, :before => Proc.new { 1.week.from_now }
validates_date :entry_date, :with_time => '17:00', :on_or_before => :competition_closing
@@ -126,7 +125,7 @@ be happy to know that is exactly the format you can use to define your own if
you want. No complex regular expressions or duck punching (monkey patching) the
plugin is needed.
Time formats:
Time formats:
hh:nn:ss
hh-nn-ss
h:nn
@@ -139,10 +138,10 @@ plugin is needed.
h-nn_ampm
h_ampm
NOTE: Any time format without a meridian token (the 'ampm' token) is considered
NOTE: Any time format without a meridian token (the 'ampm' token) is considered
in 24 hour time.
Date formats:
Date formats:
yyyy/mm/dd
yyyy-mm-dd
yyyy.mm.dd
@@ -152,9 +151,9 @@ plugin is needed.
d.m.yy
d mmm yy
NOTE: To use non-US date formats see US/EURO FORMATS section
NOTE: To use non-US date formats see US/EURO FORMATS section
Datetime formats:
Datetime formats:
m/d/yy h:nn:ss OR d/m/yy hh:nn:ss
m/d/yy h:nn OR d/m/yy h:nn
m/d/yy h:nn_ampm OR d/m/yy h:nn_ampm
@@ -163,7 +162,7 @@ plugin is needed.
ddd mmm d hh:nn:ss zo yyyy # Ruby time string
yyyy-mm-ddThh:nn:ss(?:Z|zo) # ISO 8601
NOTE: To use non-US date formats see US/EURO FORMATS section
NOTE: To use non-US date formats see US/EURO FORMATS section
Here is what each format token means: