# Acts\_as\_versioned

**URL:** <https://www.ruby-forum.com/t/acts-as-versioned/51160>\
**Category:** Rails\
**Created:** [December 27, 2005, 12:04pm UTC](https://www.ruby-forum.com/t/acts-as-versioned/51160 "2005-12-27T12:04:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michiel\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@Michiel\_S](https://www.ruby-forum.com/u/Michiel_S)\
**Post date:** [December 27, 2005, 12:04pm UTC](https://www.ruby-forum.com/t/acts-as-versioned/51160/1 "2005-12-27T12:04:58Z")

</div>

Hi,

I’m integrating acts\_as\_versioned ([ar-versioned.rubyforge.org](http://ar-versioned.rubyforge.org)) in my  
customized CMS rails application to set up revision control for pages.  
Getting and viewing versions works allright, but when I try to revert  
to a version in the following way, nothing happens to the actual data  
in the object.

Link from page:

\<%= link\_to image\_tag(‘revert’), :action =\> ‘do\_revert’, :id =\> @page,  
:version =\> version %\>

in my controller:

def do\_revert  
page = Page.find(params[:id])  
page.revert\_to!(params[:version])  
flash[:notice] = page.title  
redirect\_to :action =\> ‘edit’, :id =\> params[:id]  
end

When I look at the data in the object, nothing seems to have changed.

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![Michiel\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@Michiel\_S](https://www.ruby-forum.com/u/Michiel_S)\
**Post date:** [December 27, 2005, 12:40pm UTC](https://www.ruby-forum.com/t/acts-as-versioned/51160/2 "2005-12-27T12:40:15Z")

</div>

Seems you forgot to call ‘page.save’ after  
page.revert\_to!(params[:version])

David

Michiel S. wrote:

> Hi,
> 
> I’m integrating acts\_as\_versioned ([ar-versioned.rubyforge.org](http://ar-versioned.rubyforge.org)) in my  
> customized CMS rails application to set up revision control for pages.  
> Getting and viewing versions works allright, but when I try to revert  
> to a version in the following way, nothing happens to the actual data  
> in the object.
> 
> Link from page:
> 
> \<%= link\_to image\_tag(‘revert’), :action =\> ‘do\_revert’, :id =\> @page,  
> :version =\> version %\>
> 
> in my controller:
> 
> def do\_revert  
> page = Page.find(params[:id])  
> page.revert\_to!(params[:version])  
> flash[:notice] = page.title  
> redirect\_to :action =\> ‘edit’, :id =\> params[:id]  
> end
> 
> When I look at the data in the object, nothing seems to have changed.
> 
> Thanks in advance,

---

<div class="post-metadata">

**Author:** ![Michiel\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@Michiel\_S](https://www.ruby-forum.com/u/Michiel_S)\
**Post date:** [December 27, 2005, 1:26pm UTC](https://www.ruby-forum.com/t/acts-as-versioned/51160/3 "2005-12-27T13:26:19Z")

</div>

On 12/27/05, Michiel S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= link\_to image\_tag(‘revert’), :action =\> ‘do\_revert’, :id =\> @page,
> 
> When I look at the data in the object, nothing seems to have changed.
> 
> Thanks in advance,

A good rule of thumb: whenever your models aren’t saving, check the  
validations and callbacks.

## Assuming you have plugin loaded, run the unit tests to be sure acts\_as\_versioned is working: rake test\_plugins PLUGIN=acts\_as\_versioned. You will have to create a test db if you run against a specific database (sqlite is the default): rake test\_plugins PLUGIN=acts\_as\_versioned DB=mysql.

rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![Michiel\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@Michiel\_S](https://www.ruby-forum.com/u/Michiel_S)\
**Post date:** [December 27, 2005, 7:45pm UTC](https://www.ruby-forum.com/t/acts-as-versioned/51160/4 "2005-12-27T19:45:29Z")

</div>

2005/12/27, Michiel S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> a version number or  
> an instance of the versioned model
> 
> I’ve also tried using normal revert\_to(version) and page.save after  
> that. Both didn’t work.

Ok, I’ve found the solution. I never thought about the difference  
between a version id, and the number of the version for a specific  
model. So using the object ‘version’ in my partial to link to the  
revert method actually passes on the real id of the version row in  
page\_versions, and not the version number of the version for the  
actual model.

So I need to pass on version.version instead of version. Solved it  
now, thanks for your help guys 🙂 And Rick, thanks for this plugin!

Cheers,  
Michiel

---

<div class="post-metadata">

**Author:** ![Michiel\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@Michiel\_S](https://www.ruby-forum.com/u/Michiel_S)\
**Post date:** [December 27, 2005, 4:39pm UTC](https://www.ruby-forum.com/t/acts-as-versioned/51160/5 "2005-12-27T16:39:36Z")

</div>

2005/12/27, David M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Seems you forgot to call ‘page.save’ after  
> page.revert\_to!(params[:version])

However, the API doc says:

revert\_to!(version)

Reverts a model to a given version and saves the model. Takes either  
a version number or  
an instance of the versioned model

I’ve also tried using normal revert\_to(version) and page.save after  
that. Both didn’t work.
