Forum: Ruby on Rails acts_as_versioned

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Michiel S. (Guest)
on 2005-12-27 13:04
(Received via mailing list)
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,
David M. (Guest)
on 2005-12-27 13:40
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,
Rick O. (Guest)
on 2005-12-27 14:26
(Received via mailing list)
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
Michiel S. (Guest)
on 2005-12-27 17:39
(Received via mailing list)
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.
Michiel S. (Guest)
on 2005-12-27 20:45
(Received via mailing list)
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 :) And Rick, thanks for this plugin!

Cheers,
Michiel
This topic is locked and can not be replied to.