aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/touch_later.rb
diff options
context:
space:
mode:
authorBen Standefer <benstandefer@gmail.com>2016-06-01 12:03:30 -0700
committerBen Standefer <benstandefer@gmail.com>2016-07-02 16:16:56 -0700
commitac156060a4dd81ea1f7730affb1491ceb3c973d0 (patch)
tree874a4b44ed7efbc1baffde1ec589b9ae88cebc67 /activerecord/lib/active_record/touch_later.rb
parent6a77398cc194070da00dc8e5bea773fa7b792444 (diff)
downloadrails-ac156060a4dd81ea1f7730affb1491ceb3c973d0.tar.gz
rails-ac156060a4dd81ea1f7730affb1491ceb3c973d0.tar.bz2
rails-ac156060a4dd81ea1f7730affb1491ceb3c973d0.zip
Improve error message when record touch fails.
The current error message only indicates that a touch can fail because the record is new. In practice, we saw cases where touches were failing because the record had been destroyed. `persisted?` checks `new_record?` *and* `destroyed?`. It was confusing to get a message about a new record when in reality we were destroying records. I also included a helpful tip for users to consider using `persisted?`, `new_record?`, or `destroyed?` before touching.
Diffstat (limited to 'activerecord/lib/active_record/touch_later.rb')
-rw-r--r--activerecord/lib/active_record/touch_later.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/touch_later.rb b/activerecord/lib/active_record/touch_later.rb
index 9a80a63e28..5c41ab6e39 100644
--- a/activerecord/lib/active_record/touch_later.rb
+++ b/activerecord/lib/active_record/touch_later.rb
@@ -8,7 +8,12 @@ module ActiveRecord
end
def touch_later(*names) # :nodoc:
- raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
+ unless persisted?
+ raise ActiveRecordError, <<-end_error.strip_heredoc
+ cannot touch on a new or destroyed record object. Consider using
+ persisted?, new_record?, or destroyed? before touching
+ end_error
+ end
@_defer_touch_attrs ||= timestamp_attributes_for_update_in_model
@_defer_touch_attrs |= names