# Questions on acts\_as\_versioned

**URL:** <https://www.ruby-forum.com/t/questions-on-acts-as-versioned/122511>\
**Category:** Rails\
**Created:** [December 8, 2007, 3:53pm UTC](https://www.ruby-forum.com/t/questions-on-acts-as-versioned/122511 "2007-12-08T15:53:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonaylward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@antonaylward](https://www.ruby-forum.com/u/antonaylward)\
**Post date:** [December 8, 2007, 3:53pm UTC](https://www.ruby-forum.com/t/questions-on-acts-as-versioned/122511/1 "2007-12-08T15:53:19Z")

</div>

Thanks, Rick, for a great plugin. But one thgn leads to another, sort  
of like pulling at the thread in the willy jumper … 🙂

Three questions about acts\_as\_versioned; the second leads to other  
issues.

1. use of :sequence\_name  
is this the “order\_by”? How is this going to be different from  
using the ‘:version\_column’ to order the  
revisions.

2. Derived from (1).  
If I have a ‘:version\_column’ set and I want optimistic locking  
as well, how do I do that?

3. I’m very unclear about using ‘:extend’ or the “acts\_as\_versioned  
do … end” construct.

Obviously I want to be able to reference any revision of the Page and  
any field or method:

… something  
page.revision(rev\_no).title = “Hello World”.reverse  
page.revision(rev\_no).updated\_at.suc === page.updated\_at  
display = page.revision(rev\_no).render\_content\_to\_html

If I wasn’t using acts\_as\_versioned and was doing this with an  
explicit revision table  
I’d be writing thigns like

```
class Page < ActiveRecord::Base
   has_many :revisions
   has_one :current_revision, :class_name => 'Revision', :order =>

```

‘rev DESC’

but I’d really like to DRY and not have to have a separate Revision  
model.

Any input or examples would be appreciated.

---

<div class="post-metadata">

**Author:** ![antonaylward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@antonaylward](https://www.ruby-forum.com/u/antonaylward)\
**Post date:** [December 8, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/questions-on-acts-as-versioned/122511/2 "2007-12-08T19:18:12Z")

</div>

On 12/8/07, AntonAylward [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> revisions.
> 
> ```

This is some postgres thing, you can probably ignore it on other  
databases.

> 1. Derived from (1).  
> If I have a ‘:version\_column’ set and I want optimistic locking  
> as well, how do I do that?

I think you just set the version column to lock\_version. I’ve never  
used optimistic locking, so it may need some patches to get working  
correctly. Feel free to contribute if you do this.

> 1. I’m very unclear about using ‘:extend’ or the “acts\_as\_versioned  
> do … end” construct.

It’s similar to the :extend or block syntax of ActiveRecord  
associations, only it defines the methods on both the current class  
and the version class. For instance in Lighthouse (my Rails based  
ticket tracker app), Ticket comments are really just versions of the  
same ticket. But, I want the Ticket::Version model to quack like a  
Ticket, so I add a lot of methods and associations inside the  
acts\_as\_versioned block.

> explicit revision table  
> Any input or examples would be appreciated.  
> acts\_as\_versioned creates another class for you. Check out the code  
> ([http://projects.wh.techno-weenie.net/browser/plugins/acts\_as\_versioned/lib/acts\_as\_versioned.rb](http://projects.wh.techno-weenie.net/browser/plugins/acts_as_versioned/lib/acts_as_versioned.rb)),  
> it sets up a versions association. You can define helper methods to  
> access them by version # if you want. I suppose the current way would  
> resemble:

@page.versions.find\_by\_version(234)

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
