diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-08-24 09:56:26 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-24 11:24:32 -0300 |
commit | 747e0744dd61561c27ae1b65a74a2b7da7e3f2fe (patch) | |
tree | cdd5e57a28cdfae79d605437e9ac0c3c5c372c8c /activerecord/lib/active_record/persistence.rb | |
parent | 11f6179f55d38dd54b69aeeb5bee9053194f0e84 (diff) | |
download | rails-747e0744dd61561c27ae1b65a74a2b7da7e3f2fe.tar.gz rails-747e0744dd61561c27ae1b65a74a2b7da7e3f2fe.tar.bz2 rails-747e0744dd61561c27ae1b65a74a2b7da7e3f2fe.zip |
@user.touch should not fail if User does not have updated_at/updated_on column.
[#5439 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 0188972169..c5c40d1863 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -214,18 +214,20 @@ module ActiveRecord # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on def touch(name = nil) attributes = timestamp_attributes_for_update_in_model - attributes << name if name + unless attributes.blank? + attributes << name if name - current_time = current_time_from_proper_timezone - changes = {} + current_time = current_time_from_proper_timezone + changes = {} - attributes.each do |column| - changes[column.to_s] = write_attribute(column.to_s, current_time) - end + attributes.each do |column| + changes[column.to_s] = write_attribute(column.to_s, current_time) + end - @changed_attributes.except!(*changes.keys) - primary_key = self.class.primary_key - self.class.update_all(changes, { primary_key => self[primary_key] }) == 1 + @changed_attributes.except!(*changes.keys) + primary_key = self.class.primary_key + self.class.update_all(changes, { primary_key => self[primary_key] }) == 1 + end end private |