diff options
author | Akira Matsuda <ronnie@dio.jp> | 2010-12-16 18:31:31 +0900 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-02-01 12:21:18 -0200 |
commit | 817e37013610c8e8866197594d5e408b4d5daec5 (patch) | |
tree | 0984f26e133ef7060b956e634db790299823312d /activerecord/lib | |
parent | ed2eb6fa87d1eaffa137ca38ab04b41dfd6d501b (diff) | |
download | rails-817e37013610c8e8866197594d5e408b4d5daec5.tar.gz rails-817e37013610c8e8866197594d5e408b4d5daec5.tar.bz2 rails-817e37013610c8e8866197594d5e408b4d5daec5.zip |
Make before_type_cast available for datetime fields
[#3973 state:committed]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index dc2785b6bf..a72eecb50e 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -40,12 +40,13 @@ module ActiveRecord def define_method_attribute=(attr_name) if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name]) method_body, line = <<-EOV, __LINE__ + 1 - def #{attr_name}=(time) + def #{attr_name}=(original_time) + time = original_time.dup unless time.acts_like?(:time) time = time.is_a?(String) ? Time.zone.parse(time) : time.to_time rescue time end time = time.in_time_zone rescue nil if time - write_attribute(:#{attr_name}, time) + write_attribute(:#{attr_name}, (time || original_time)) end EOV generated_attribute_methods.module_eval(method_body, __FILE__, line) |