mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Fix before_type_cast for non-dirty attributes (issue #52).
Only use before_type_cast implementation if earlier than 3.1.0 which has it's own working version for date/time fields now.
This commit is contained in:
@@ -46,7 +46,7 @@ module ValidatesTimeliness
|
||||
def define_timeliness_before_type_cast_method(attr_name)
|
||||
method_body, line = <<-EOV, __LINE__ + 1
|
||||
def #{attr_name}_before_type_cast
|
||||
_timeliness_raw_value_for('#{attr_name}')
|
||||
_timeliness_raw_value_for('#{attr_name}') || @attributes['#{attr_name}']
|
||||
end
|
||||
EOV
|
||||
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
||||
|
||||
@@ -7,7 +7,8 @@ module ValidatesTimeliness
|
||||
def define_attribute_methods
|
||||
super
|
||||
# Define write method and before_type_cast method
|
||||
define_timeliness_methods(true)
|
||||
use_before_type_cast = ::ActiveRecord::VERSION::STRING < '3.1.0'
|
||||
define_timeliness_methods(use_before_type_cast)
|
||||
end
|
||||
|
||||
def timeliness_attribute_timezone_aware?(attr_name)
|
||||
|
||||
Reference in New Issue
Block a user