module Trashable
extend ActiveSupport::Concern
included do
scope :trashed, -> { unscope(where: :trashed_at).where.not(trashed_at: nil) }
scope :without_trashed, -> { where(trashed_at: nil) }
scope :with_trashed, -> { unscope(where: :trashed_at) }
default_scope { without_trashed }
end
def trash!
update_column(:trashed_at, Time.zone.now)
end
def restore!
update_column(:trashed_at, nil)
end
def trashed?
trashed_at?
end
end
Useful concern to allow you to move records to the trash without deleting the record.
Please, write a migration to add the column trashed_at to your table