There might be sometimes that we get an unexpected exception where we use ActiveRecord::FinderMethods find
and find_by
.
So we need to be sure whether to use find
or find_by
where we are finding active record.
The main difference between find
and find_by
is the answer to this question, what we want to return once the record is not found? We will want to use find_by
when we want to return nil if no record is found while we use find
to expect the exception, ActiveRecord::RecordNotFound, to be raised.
To discover more about Active Record Finder Methods, please refer to the API document.
Happy coding!