Skip to content

vrinek/simple-undo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Undo

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

User model association and @logged_user

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.

Example

Run the necessary migrations:

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

Inside a model:

class SomeModel < ActiveRecord::Base
  acts_as_undoable
end

Inside a controller:

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

About

Just a simple undo plugin for ruby on rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages