Merge pull request #25241 from aguynamedben/fix-touch-error-messages
Improve error message when record touch fails.
This commit is contained in:
commit
ee50de0390
@ -479,7 +479,12 @@ def reload(options = nil)
|
||||
# ball.touch(:updated_at) # => raises ActiveRecordError
|
||||
#
|
||||
def touch(*names, time: nil)
|
||||
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
|
||||
|
||||
time ||= current_time_from_proper_timezone
|
||||
attributes = timestamp_attributes_for_update_in_model
|
||||
|
@ -8,7 +8,12 @@ module TouchLater
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user