.find_by will return a
nil when record isn’t found.
.find_by! will return
Recently in a project,
.find_by() was being used to find records referenced by a GUID rather than an
id. If a record couldn’t be found the server would throw a
500 error. We’d rather have
404 be shown so that’s where
.find_by!() comes in.
.find_by! will return an
ActiveRecord::RecordNotFound exception with a status code of
404 rendering the 404 template instead of the error template.