aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorgbuesing <gbuesing@gmail.com>2008-05-08 20:31:54 -0500
committergbuesing <gbuesing@gmail.com>2008-05-08 20:31:54 -0500
commit328fada610aa9128386bc4b372d3e0b68aede945 (patch)
tree2499b812446d42b2a15de1b5f152771c27db445d /activerecord/lib/active_record/attribute_methods.rb
parenteb5b93be74ed3eca925c1ab9bd4739919ae39a41 (diff)
downloadrails-328fada610aa9128386bc4b372d3e0b68aede945.tar.gz
rails-328fada610aa9128386bc4b372d3e0b68aede945.tar.bz2
rails-328fada610aa9128386bc4b372d3e0b68aede945.zip
ActiveRecord time zone aware attributes: blank string is treated as nil when assigned to writer
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 973b761546..fde98bf19f 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -179,10 +179,10 @@ module ActiveRecord
def define_write_method_for_time_zone_conversion(attr_name)
method_body = <<-EOV
def #{attr_name}=(time)
- if time
- time = Time.zone.parse(time) rescue time unless time.acts_like?(:time)
- time = time.in_time_zone if time.acts_like?(:time)
+ unless time.blank? || 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)
end
EOV