mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 23:06:42 +00:00
changed back to using error_value_formats for Rails 2.0/2.1
This commit is contained in:
parent
956933f58b
commit
f4ed751c26
@ -304,7 +304,7 @@ values inserted in the error messages for temporal restrictions like so
|
|||||||
|
|
||||||
For Rails 2.0/2.1:
|
For Rails 2.0/2.1:
|
||||||
|
|
||||||
ValidatesTimeliness::Validator.default_error_value_formats.update(
|
ValidatesTimeliness::Validator.error_value_formats.update(
|
||||||
:time => '%H:%M:%S',
|
:time => '%H:%M:%S',
|
||||||
:date => '%Y-%m-%d',
|
:date => '%Y-%m-%d',
|
||||||
:datetime => '%Y-%m-%d %H:%M:%S'
|
:datetime => '%Y-%m-%d %H:%M:%S'
|
||||||
|
|||||||
@ -38,7 +38,7 @@ module ValidatesTimeliness
|
|||||||
errors = defaults['activerecord']['errors']['messages'].inject({}) {|h,(k,v)| h[k.to_sym] = v.gsub(/\{\{\w*\}\}/, '%s');h }
|
errors = defaults['activerecord']['errors']['messages'].inject({}) {|h,(k,v)| h[k.to_sym] = v.gsub(/\{\{\w*\}\}/, '%s');h }
|
||||||
::ActiveRecord::Errors.default_error_messages.update(errors)
|
::ActiveRecord::Errors.default_error_messages.update(errors)
|
||||||
|
|
||||||
ValidatesTimeliness::Validator.default_error_value_formats = defaults['validates_timeliness']['error_value_formats'].symbolize_keys
|
ValidatesTimeliness::Validator.error_value_formats = defaults['validates_timeliness']['error_value_formats'].symbolize_keys
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,6 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
class Validator
|
class Validator
|
||||||
cattr_accessor :ignore_restriction_errors
|
cattr_accessor :ignore_restriction_errors
|
||||||
cattr_accessor :default_error_value_formats
|
|
||||||
|
|
||||||
self.ignore_restriction_errors = false
|
self.ignore_restriction_errors = false
|
||||||
|
|
||||||
RESTRICTION_METHODS = {
|
RESTRICTION_METHODS = {
|
||||||
@ -163,10 +161,14 @@ module ValidatesTimeliness
|
|||||||
if defined?(I18n)
|
if defined?(I18n)
|
||||||
I18n.translate('validates_timeliness.error_value_formats')
|
I18n.translate('validates_timeliness.error_value_formats')
|
||||||
else
|
else
|
||||||
default_error_value_formats
|
@@error_value_formats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error_value_formats=(formats)
|
||||||
|
@@error_value_formats = formats
|
||||||
|
end
|
||||||
|
|
||||||
def evaluate_option_value(value, type, record)
|
def evaluate_option_value(value, type, record)
|
||||||
case value
|
case value
|
||||||
when Time, Date
|
when Time, Date
|
||||||
|
|||||||
@ -563,8 +563,8 @@ describe ValidatesTimeliness::Validator do
|
|||||||
if defined?(I18n)
|
if defined?(I18n)
|
||||||
I18n.backend.store_translations 'en', :validates_timeliness => { :error_value_formats => custom }
|
I18n.backend.store_translations 'en', :validates_timeliness => { :error_value_formats => custom }
|
||||||
else
|
else
|
||||||
@@formats = ValidatesTimeliness::Validator.default_error_value_formats
|
@@formats = ValidatesTimeliness::Validator.error_value_formats
|
||||||
ValidatesTimeliness::Validator.default_error_value_formats = custom
|
ValidatesTimeliness::Validator.error_value_formats = custom
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -590,7 +590,7 @@ describe ValidatesTimeliness::Validator do
|
|||||||
if defined?(I18n)
|
if defined?(I18n)
|
||||||
I18n.reload!
|
I18n.reload!
|
||||||
else
|
else
|
||||||
ValidatesTimeliness::Validator.default_error_value_formats = @@formats
|
ValidatesTimeliness::Validator.error_value_formats = @@formats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user