Project

archivable

0.01
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Archive your Rails models rather than delete them, with model and controller concerns.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
>= 0
>= 0

Runtime

 Project Readme

archivable Build Status

Archive your Rails models rather than delete them. This provides the archiving functionality app so you can do the following:

In your models
user.archived?  #=> false
user.archive!   #=> true
user.archived?  #=> true
user.unarchive! #=> true
user.archived?  #=> false
In your views
<% if user.archived? %>
  <%= link_to :Archive, archive_user_path(user) %>
<% else %>
  <%= link_to :Unarchive, archive_user_path(user) %>
<% end %>

Installation

Add this line to your application's Gemfile:

gem 'archivable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install archivable

Usage

Database Migration

First, you need to add the archived column to your model (which we we call User for this example):

$ rails g migration add_archived_to_users archived:boolean
$ rake db:migrate

NOTE: remember to edit the migration and set :archived column to default to false in order to simplify querying for non-archived models.

  add_column :users, :archived, :boolean, default: false

Application Routes

In your routes file (config/routes.rb):

My::Application.routes.draw do
  resources :users do
    get archive,  on: :member
    get archived, on: :collection
  end
end

The Model

Next, you need to include the model concern to gain access to some handy methods.

class User < ActiveRecord::Base
  include Archivable::Model

  # ...
end

The Controller

Lastly, you need to include the controller concern to handle the controller actions.

class UsersController < ApplicationController
  include Archivable::Controller

  def index
    @users = User.where(archived: false)
  end

  # ...
end

That's it.

Now, instead of a delete link, you can do the following:

<%= link_to user.archived? ? :Unarchive : :Archive, archive_user_path(user) %>
<%= link_to 'See Archived Users', archived_users_path %>

Contributing

  1. Fork it ( http://github.com/johnotander/archivable/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request