HowFlow


http://github.com/ajh/acts_as_soft_deletable/tree/master
github.com Temporarily delete records from AR models: This plugin provides the ability to soft delete ActiveRecord models. When models are destroyed, they will be archived into a special deleted table. They can later be restored easily.

Share it!   Posted by Avatar flood 7 months ago

Example usage, just to give you an idea how it works:


class Artist < ActiveRecord::Base
  acts_as_soft_deletable # This will wrap the destroy method to provide soft delete        
                         # support and create a new ActiveRecord class called Artist::Deleted
end

model = Artist.find(34)
model.destroy   # removes row from artists table, and adds a row to
                # deleted_artists table

deleted = Artist::Deleted.find(34)
deleted.undestroy!  # adds the row back to the artists table, and removes
                    # if from the deleted_artists table

restored = Artist.find(34) # The artist is restored with all the same
                           # information. The updated_at column will be
                           # Time.now if it exists.

Take a look at the README to find out more. For more Rails Tricks, click here



Please log in or sign up and vote for this trick if it was helpful for you.
Don't forget to subscribe to our RSS Feed RSS/Atom feed to get the latest tricks.