I want to check if a record already exists in a database, and return true
or false
.
If it exists, I want to update the update_at
datetime field. The method touch_with_version
from the paper_trail
gem will do it.
Which is better?
def repeated?(unprocessed)
occurrence = Occurrence.find_by(unprocessed: unprocessed)
occurrence.touch_with_version if occurrence.present?
occurrence.present?
end
Or
def repeated?(unprocessed)
occurrence = Occurrence.find_by(unprocessed: unprocessed)
if occurrence.present?
occurrence.touch_with_version
true
else
false
end
end
Is there a better way?