Module ActiveRecord::Acts::Versioned
In: lib/acts_as_versioned.rb

Specify this act if you want to save a copy of the row in a versioned table. This assumes there is a versioned table ready and that your model has a version field. This works with optimisic locking if the lock_version column is present as well.

The class for the versioned model is derived the first time it is seen. Therefore, if you change your database schema you have to restart your container for the changes to be reflected. In development mode this usually means restarting WEBrick.

  class Page < ActiveRecord::Base
    # assumes pages_versions table


  page = Page.create(:title => 'hello world!')
  page.version       # => 1

  page.title = 'hello world'
  page.version       # => 2
  page.versions.size # => 2

  page.revert_to(1)  # using version number
  page.title         # => 'hello world!'

  page.revert_to(page.versions.last) # using versioned instance
  page.title         # => 'hello world'

See ActiveRecord::Acts::Versioned::ClassMethods#acts_as_versioned for configuration options

Classes and Modules

Module ActiveRecord::Acts::Versioned::ActMethods
Module ActiveRecord::Acts::Versioned::ClassMethods