Merge pull request #25241 from aguynamedben/fix-touch-error-messages

Improve error message when record touch fails.
This commit is contained in:
Richard Schneeman 2016-07-03 10:35:31 -05:00 committed by GitHub
commit ee50de0390
2 changed files with 12 additions and 2 deletions

@ -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