Acts_as_versioned delete a specific version
June 26, 2009
Environment: Rails 2.3.2, Windows Vista, SQLite3 development on a local box
By default acts_as_versioned has a method to delete up to :limit of versions called clear_old_versions. If you need to delete a specific version, the following does not work: @artist.versions.delete(id) because a String is passed instead of a Versioned class.
But you can specify your own method, which is a very easy modification of the clear_old_versions:
def clear_old_version(version)
self.class.versioned_class.delete_all ["#{self.class.version_column} = ? and #{self.class.versioned_foreign_key} = ?", version, id]
end
And now you can call this method like this: @artist.clear_old_version(params[:version_id])
artist_controller.rb:
def deleteversion @artist = Artist.find(params[:artist_id]) @artist.clear_old_version(params[:version_id]) redirect_to :action => 'show', :id => @artist end
Entry Filed under: Uncategorized. .
Trackback this post | Subscribe to the comments via RSS Feed