Skip to content

Instantly share code, notes, and snippets.

@acidlabs-snippets
Created October 3, 2012 19:19
Show Gist options
  • Save acidlabs-snippets/3829167 to your computer and use it in GitHub Desktop.
Save acidlabs-snippets/3829167 to your computer and use it in GitHub Desktop.
Softdelete for Rails models #rails #softdelete
module ModuleName
extend ActiveSupport::Concern
module InstanceMethods
def destroy
run_callbacks :destroy do
if self.respond_to? :deleted
self.deleted = true
self.save(validate: false)
else
raise "deleted attribute not found in model"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment