mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 14:56:43 +00:00
tweaked doc examples and added message options
This commit is contained in:
parent
9cf994564e
commit
80ed110efc
25
README
25
README
@ -61,17 +61,22 @@ The validation methods take the usual options plus some specific ones to restric
|
|||||||
the valid range of dates or times allowed
|
the valid range of dates or times allowed
|
||||||
|
|
||||||
Temporal options:
|
Temporal options:
|
||||||
|
|
||||||
:before - Attribute must be before this value to be valid
|
: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
|
: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
|
: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
|
:on_or_after - Attribute must be equal to or after this value to be valid
|
||||||
|
|
||||||
Regular validation options:
|
Regular validation options:
|
||||||
|
|
||||||
:allow_nil - Allow a nil value to be valid
|
:allow_nil - Allow a nil value to be valid
|
||||||
:allow_blank - Allows a nil or empty string value to be valid
|
:allow_blank - Allows a nil or empty string value to be valid
|
||||||
|
|
||||||
|
Message options: - Use these to override the default error messages
|
||||||
|
:invalid_datetime_message
|
||||||
|
:before_message
|
||||||
|
:on_or_before_message
|
||||||
|
:after_message
|
||||||
|
:on_or_after_message
|
||||||
|
|
||||||
The temporal options can take 4 different value types:
|
The temporal options can take 4 different value types:
|
||||||
|
|
||||||
* String date or time value
|
* String date or time value
|
||||||
@ -85,11 +90,13 @@ as dates.
|
|||||||
|
|
||||||
== EXAMPLES:
|
== EXAMPLES:
|
||||||
|
|
||||||
validates_date :date_of_birth, :on_or_after => '1900-01-01',
|
validates_date :date_of_birth :before => Proc.new { 18.years.ago },
|
||||||
:before => Date.new(1980, 1, 1)
|
:before_message => "must be at least 18 years old"
|
||||||
|
|
||||||
validates_time :breakfast_time, :on_or_after => '6:00am',
|
validates_time :breakfast_time, :on_or_after => '6:00am',
|
||||||
:before => :second_breakfast_time
|
:before => :second_breakfast_time,
|
||||||
|
:on_or_after_message => 'must after opening time',
|
||||||
|
:allow_nil => true
|
||||||
|
|
||||||
validates_datetime :appointment_date, :before => Proc.new { 1.week.from_now }
|
validates_datetime :appointment_date, :before => Proc.new { 1.week.from_now }
|
||||||
|
|
||||||
@ -231,9 +238,15 @@ an example of using Chronis instead. Put this into a file in the lib directory.
|
|||||||
|
|
||||||
class ActiveRecord::Base
|
class ActiveRecord::Base
|
||||||
|
|
||||||
def self.parse_date_time(raw_value, type)
|
def self.parse_date_time_with_chronic(raw_value, type, strict=true)
|
||||||
|
# You can ignore type and strict with Chronic
|
||||||
|
Chronic.parse(raw_value)
|
||||||
|
|
||||||
|
# You could also fallback to normal plugin with
|
||||||
|
#rescue
|
||||||
|
# parse_date_time_without_chronic
|
||||||
end
|
end
|
||||||
|
alias_method_chain :parse_date_time, :chronic
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user