From 325bb0dbe778b92e55621be450af6e3384ff31c5 Mon Sep 17 00:00:00 2001 From: Kevin Pheasey Date: Fri, 14 Oct 2016 20:31:12 -0400 Subject: [PATCH] Ensure a nil timestamp_attribute is not added to touch_updates --- lib/active_touch/touch.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/active_touch/touch.rb b/lib/active_touch/touch.rb index bd6bb9c..8fdee7a 100644 --- a/lib/active_touch/touch.rb +++ b/lib/active_touch/touch.rb @@ -13,14 +13,16 @@ def initialize(record, association, options = {}) end def run - touch_updates[ActiveTouch.configuration.timestamp_attribute] = record.updated_at + if !ActiveTouch.configuration.timestamp_attribute.nil? + touch_updates[ActiveTouch.configuration.timestamp_attribute] = record.updated_at + end if associated.is_a? ActiveRecord::Base - associated.update_columns(touch_updates) if !ActiveTouch.configuration.timestamp_attribute.nil? && !is_touched + associated.update_columns(touch_updates) if !touch_updates.empty? && !is_touched associated.send(after_touch) unless after_touch.blank? elsif !associated.nil? - associated.update_all(touch_updates) if !ActiveTouch.configuration.timestamp_attribute.nil? && !is_touched + associated.update_all(touch_updates) if !touch_updates.empty? && !is_touched associated.each { |associate| associate.send(after_touch) } unless after_touch.blank? end end