Acts_as_versioned


#1

Hi,

I’m integrating acts_as_versioned (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,


#2

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) 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,


#3

On 12/27/05, Michiel S. 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


#4

2005/12/27, Michiel S. 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 :slight_smile: And Rick, thanks for this plugin!

Cheers,
Michiel


#5

2005/12/27, David M. 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.