I'm trying to roll my own archiving in rails, but I'm having trouble figuring out how to alias the old destroy method before overriding it. Below is what I would like to do, but I get a NoMethodError because destroy isn't defined before that in the module. It works the way I'd expect if I put it in an InstanceMethods module, but that appears to be deprecated. Should I just handle it with a vanilla module or is there a way to do it with ActiveSupport::Concern?
module Trashable
extend ActiveSupport::Concern
included do
default_scope where(deleted_at: nil)
end
module ClassMethods
def deleted
self.unscoped.where(self.arel_table[:deleted_at].not_eq(nil))
end
end
alias_method :destroy!, :destroy
def destroy
run_callbacks(:destroy) do
update_column(:deleted_at, Time.now)
end
end
end