Kakurenbo provides soft delete. Kakurenbo is a re-implementation of paranoia and acts_as_paranoid for Rails4. implemented a function that other gems are not enough.
The usage of the Kakurenbo is very very very simple. Only add deleted_at
(datetime) to column.
Of course you can use acts_as_paranoid
.In addition, Kakurenbo has many advantageous.
You should use kakurenbo-puti!
gem 'kakurenbo'
You need only to add 'deleted_at' to model.
rails generate migration AddDeletedAtToModels deleted_at:datetime
The model having deleted_at becomes able to soft-delete automatically.
Kakurenbo provides acts_as_paranoid
method for compatibility.
# if action is cancelled by callbacks, return false.
model.destroy
# if action is cancelled by callbacks, raise ActiveRecord::RecordNotDestroyed.
model.destroy!
# selected model will be destroyed.
Model.where(:foo => 'bar').destroy_all
when want without callbacks.
model.delete
# selected model will be deleted.
Model.where(:foo => 'bar').delete_all
# if action is cancelled by callbacks, return false.
model.restore
# if action is cancelled by callbacks, raise ActiveRecord::RecordNotRestored.
model.restore!
When restore, call restore callbacks.before_restore
after_restore
Use hard option.
model.destroy(hard: true)
# without callbacks.
model.delete(hard: true)
# selected model will be destroyed.
Model.where(:foo => 'bar').destroy_all(nil, hard: true)
# selected model will be destroyed.
Model.where(:foo => 'bar').delete_all(nil, hard: true)
model.destroyed?
Model.with_deleted
Model.only_deleted
This gem is released under the MIT license.