The #new_record? function determines if a record has been saved. But it is always false in the after_save hook. Is there a way to determine whether the record i
after_save
Rails 5.1+ way:
user = User.new user.save! user.saved_change_to_attribute?(:id) # => true
Yet another option, for those who do have an updated_at timestamp:
updated_at
if created_at == updated_at # it's a newly created record end