mark_as_deleted is a small gem which simplifies adding 'marked as deleted' functionality to your models.
Installation
gem install mark_as_deletedin your console, or
gem 'mark_as_deleted'in your Gemfile.
Usage
Simply add a deleted boolean column to your model table and call mark_as_deleted in that model definition, and you are ready to go.
class Post < ActiveRecord::Base
mark_as_deleted
endNow the Post#destroy method won't erase the record from the database, it will update the deleted column to true instead.
If you want to give the column another name, you should just pass that name to the mark_as_deleted call, like so:
class Post < ActiveRecord::Base
mark_as_deleted :is_deleted
endOf course you must have a column by that name in your table.
Roadmap
-
ActiveRecordscopes based on deleted column - Maybe a generator creating a migration and adding
mark_as_deletedto the model - Maybe other ORMs support
Contributing
Fork the repository, push your changes to a topic branch and send me a pull request.