Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Trash for Rails models using scopes. (KISS)

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 rails-trash.gemspec
README.md

Rails Trash

Simple trash for your models setting the deleted_at to Time.now.utc.

Installing

Add it to your Gemfile:

gem 'rails-trash'
# gem 'rails-trash', :git => 'https://github.com/fesplugas/rails-trash.git'

Usage

Add to your entries the deleted_at attribute:

add_column :entries, :deleted_at, :timestamp

And use it on your models.

class Post < ActiveRecord::Base
  include Rails::Trash
  default_scope where(arel_table[:deleted_at].eq(nil)) if arel_table[:deleted_at]
end

Get all deleted entries:

Entry.deleted

Restore an element from trash:

Entry.restore(1)

Find an element in the trash:

Entry.find_in_trash(1)

Copyright (c) 2011-2013 Francesc Esplugas Marti, released under the MIT license

Something went wrong with that request. Please try again.