Rails & Acts-as-versioned: How would you restfully revert records?

I've never used acts-as-versioned in particular, but when I come across similar scenarios, the way I usually solve it is by reification of the attribute. In other words, I'd create a new resource only for the actual version number of the resource.

I've never used acts-as-versioned in particular, but when I come across similar scenarios, the way I usually solve it is by reification of the attribute. In other words, I'd create a new resource only for the actual version number of the resource. Eg.

/resources/:id/actual_version would point to the actual version number of the resource with id :id. Then to change the actual version, we can just PUT desired number to it. PUT /resources/:id/actual_version :version = 123 would revert our resource to the version 123.As a convention, I'd use something like "last-but-one" as a value of :version to refer to the version that preceded the actual one.

Then, to rollback the actual version, we can just do: PUT /resources/:id/actual_version :version=last-but-one -- Expanding my own answer: In routes. Rb we can do something like: map. Connect '/resources/:id/actual_version', :controller => 'resources', :action => 'set_version', :conditions => { :method => :put } And in resources_controller.

Rb: def set_version @resource = Resource. Find_by_id(params:id) if params:version && @resource version = params:version == "last-but-one"? @resource.versions.

Last : params:version if @resource. Revert_to(version) # Success, everything went fine! Else # Error, the resource couldn't be reverted - unexisting version?

End else # Error, version number or resource id is missing. End end Hope that clarified my previous thoughts a bit. ;).

I'll assume you're rolling your own system. My answer does not relate to any particular versioning plugin. Because your URLs are paths to resources, I would consider the revision parameter as optional.

You can leave it out, and get the latest revision, or specify the revision eplicitly. GET /pages/1 GET /pages/1? Revision=4 Same goes for editing.

GET /pages/1/edit GET /pages/1/edit? Revision=4 PUT to /pages/1 would create a new revision, incrementing the version number by one. The new version number is created without regard to the current revision number.It's merely a starting point when editing.

Obviously, it should be impossible to specify a revision for a POST to /pages (create). If you want to track reverts in particular, and the editing starting point mentioned above isn't sufficient, there are a few sensible alternatives. I'm not a REST geek, so I'm not sure which you should choose.

Perhaps it's a matter of taste. PUT /pages/1/revisions/4 PUT /pages/1/revert_to? Revision=4 PUT /pages/1?

Revision=4 A code example for the first alternative: # config/routes. Rb map. Resources :pages do |page| page.

Resources :revisions end # app/controllers/revisions_controller. Rb class RevisionsController Find(params:page_id) # page_id is via /pages/page_id/revisions/4 @revision = @page.revisions. Find_by_version_number(params:id) @revision.

Revert end end # app/models/revision. Rb class Revision.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions