Rails 6.1 introduced the previously_new_record? method in ActiveRecord, which determines if a record was newly created before the last save operation. This method is particularly useful when working with create_or_find_by or find_or_create_by methods, where new_record? won't work since the record is already persisted. The method enables developers to trigger specific logic like onboarding flows or logging only for newly created records.
Sort: