Skip to content

Commit 6c0fd9f

Browse files
committed
Merge pull request rails#25668 from kamipo/use_squish_rather_than_strip_heredoc
Use `squish` rather than `strip_heredoc`
1 parent 2262bd0 commit 6c0fd9f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

activerecord/lib/active_record/persistence.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,12 @@ def reload(options = nil)
479479
# ball.touch(:updated_at) # => raises ActiveRecordError
480480
#
481481
def touch(*names, time: nil)
482-
raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
482+
unless persisted?
483+
raise ActiveRecordError, <<-MSG.squish
484+
cannot touch on a new or destroyed record object. Consider using
485+
persisted?, new_record?, or destroyed? before touching
486+
MSG
487+
end
483488

484489
time ||= current_time_from_proper_timezone
485490
attributes = timestamp_attributes_for_update_in_model

activerecord/lib/active_record/touch_later.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ module TouchLater
88
end
99

1010
def touch_later(*names) # :nodoc:
11-
raise ActiveRecordError, "cannot touch on a new record object" unless persisted?
11+
unless persisted?
12+
raise ActiveRecordError, <<-MSG.squish
13+
cannot touch on a new or destroyed record object. Consider using
14+
persisted?, new_record?, or destroyed? before touching
15+
MSG
16+
end
1217

1318
@_defer_touch_attrs ||= timestamp_attributes_for_update_in_model
1419
@_defer_touch_attrs |= names

0 commit comments

Comments
 (0)