This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Mon Aug 18 07:38:25 -0700 2008 | [kivanio] |
| |
README | Fri Aug 22 14:00:09 -0700 2008 | [kivanio] |
| |
Rakefile | Mon Aug 18 07:38:25 -0700 2008 | [kivanio] |
| |
init.rb | Mon Aug 18 19:23:46 -0700 2008 | [kivanio] |
| |
lib/ | Tue Sep 02 14:26:53 -0700 2008 | [kivanio] |
| |
test/ | Mon Aug 18 07:38:25 -0700 2008 | [kivanio] |
README
ActsAsDeleted
=============
Rails plugin to hide records instead of delete.
Install plugin:
script/plugin install git://github.com/kivanio/acts_as_deleted.git
Example
=======
In your migration:
class CreateCars < ActiveRecord::Migration
def self.up
create_table :cars do |t|
t.string :name
# Use "deletestamps" to create columns "deleted" and "deleted_at"
# With argument "true", will be create a column "deleted_id" to use with restful-authentication plugin
t.deletestamps(true)
t.timestamps
end
end
def self.down
drop_table :cars
end
end
In your model:
class Car < ActiveRecord::Base
# default names scopes: "with_deleted" and "without_deleted"
acts_as_deleted
# You can set names of scopes
acts_as_deleted(:deleteed,:no_deleteed)
end
After that in your Controller:
class CarController < ApplicationController
# Use scope "without_deleted" to find normal records
def normal_records
@cars = Car.without_deleted.find :all
end
# Use scope "with_deleted" to find deleted records
def deleted_records
@cars = Car.with_deleted.find :all
end
# Use custom scope "deleteed" to find normal records
def normal_records
@cars = Car.deleteed.find :all
end
# Use custom scope "no_deleteed" to find deleted records
def deleted_records
@cars = Car.no_deleteed.find :all
end
#Use just normal find of rails to get all records
def all
@cars = car.find :all
end
# In destroy action use "delete" method to hide a record
def destroy
@car = Car.find(params[:id])
if @car.delete
flash[:notice] = 'Bye Bye Car.'
end
redirect_to(cars_url)
end
# When you use plugin restful-authentication, you can use "delete_with_user" to save user
def destroy_with_user
@car = Car.find(params[:id])
if @car.delete_with_user(current_user.id)
flash[:notice] = 'Bye Bye Car.'
end
redirect_to(cars_url)
end
end
TIPS:
To use validates_uniqueness_of with this plugin, you should use option :scope of validates_uniqueness_of.
validates_uniqueness_of :name, :scope => :deleted
Will be validated "name AND deleted" instead of only "name"
Very simple!
Like?
Recommend: http://www.workingwithrails.com/recommendation/new/person/5679-kivanio-pereira-barbosa
Copyright (c) 2008 [Kivanio Barbosa] http://www.kivanio.com.br , released under the MIT license





