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, -- Michiel Sikkes michiel.sikkes@gmail.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Seems you forgot to call ''page.save'' after page.revert_to!(params[:version]) David Michiel Sikkes 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,-- Posted via http://www.ruby-forum.com/.
On 12/27/05, Michiel Sikkes <michiel.sikkes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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,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
2005/12/27, David Marko <dmarko@tiscali.cz>:> 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 Sikkes michiel.sikkes@gmail.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
2005/12/27, Michiel Sikkes <michiel.sikkes@gmail.com>:> 2005/12/27, David Marko <dmarko@tiscali.cz>: > > 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.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 -- Michiel Sikkes michiel.sikkes@gmail.com _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Apparently Analagous Threads
- form_remote, getting data from submit
- Keep ketting weird error, NoMethodError in Admin#create_survey Keep getting ''undefined method `assign_variables_from_controller'' for #<Survey:0xb7462244>''
- *Very* basic layout question
- Rails 4: Should a HEAD request not be handled like a GET for CSRF protection?
- acts_as_versioned gem