undo is a simple undo plugin for Rails 2. It makes use of dirty updates (feature of Rails 2.2 if I recall correctly).
What it does:
-
keep track of changes done to an object (create, update, destroy)
-
changes done to various objects inside a designated block in a controller are saved as a single UndoAction
-
actions are user-specific
-
max undo limit is 1 per user
What it doesn’t:
-
redo
-
keep track of relationships between models (except belongs_to associations)
What it will do aka TODO:
-
add configuration
This plugin expects your rails app to have a User model and a @logged_user
to be set before calling a snap block. If you do not want to use this association just set @logged_user = 0
before you call a snap block in your controllers.
create a new migration
ruby script/generate migration add_simple_undo_tables
copy the contents of vendor/plugins/simple-undo/db/migrate/add_simple_undo.rb
to the generated migration
class SomeModel < ActiveRecord::Base acts_as_undoable end
class SomeController < ApplicationController undo_methods def update snap do # make some updates end end # undoing the last action of user @logged_user def undo UndoAction.by_user(@logged_user).last.undo end # undoing the last change of a specific item def undo_specific_change @item.undo_snapshots.last.undo_action.undo end end
Copyright © 2009 Kostas Karachalios, released under the WTFPL license