Module: ActiveRecord::Acts::Versioned

Defined in:
lib/junebug/ext/acts_as_versioned.rb

Overview

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
  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'

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

Defined Under Namespace

Modules: ActMethods, ClassMethods

Constant Summary collapse

CALLBACKS =
[:set_new_version, :save_version_on_create, :save_version, :clear_changed_attributes]

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



55
56
57
# File 'lib/junebug/ext/acts_as_versioned.rb', line 55

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