Module: ActiveRecord::Acts::Versioned Deprecated

Defined in:
lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb

Overview

Deprecated.

Removed at 4.0.0

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 optimistic 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
  acts_as_versioned
end

Example:

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

page.title = 'hello world'
page.save
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'

page.versions.earliest # efficient query to find the first version
page.versions.latest   # efficient query to find the most recently created version

Simple Queries to page between versions

page.versions.before(version) 
page.versions.after(version)

Access the previous/next versions from the versioned model itself

version = page.versions.latest
version.previous # go back one version
version.next     # go forward one version

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

Since:

  • 2.0.0

Defined Under Namespace

Modules: ActMethods, ClassMethods

Constant Summary collapse

CALLBACKS =
[:set_new_version, :save_version_on_create, :save_version?, :clear_altered_attributes]

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



70
71
72
# File 'lib/plugins/acts_as_versioned/lib/acts_as_versioned.rb', line 70

def self.included(base) # :nodoc:
  base.extend ClassMethods
end