forked from peterzatncs/change_log
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b87bf6c
commit 7205c86
Showing
2 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2011 PETER ZHANG | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,69 @@ | ||
Author: Peter Zhang | ||
h1. Change Log | ||
|
||
A gem to keep all maintenances in database | ||
|
||
|
||
h2. Install Change Log Gem | ||
1. command: | ||
<pre><code># gem install change_log</code</pre> | ||
|
||
2. bundler | ||
<pre><code> | ||
# Gemfile in your application | ||
gem 'change_log','0.0.1' | ||
</code</pre> | ||
then: | ||
<pre><code> | ||
bundle install | ||
</code</pre> | ||
|
||
h2. Create a table to keep all maintenance logs | ||
|
||
1. generate a migration file | ||
|
||
<pre><code> | ||
class AddChangeLog < ActiveRecord::Migration | ||
def self.up | ||
create_table :change_log do |t| | ||
t.integer :version, :null=>false # store version of each change | ||
t.string :record_id,:limit=>30 # store the actual record id | ||
t.string :table_name, :limti=>60 # store the table name | ||
t.string :attribute_name,:limit=>60 # store the column name | ||
t.string :user, :limit=>20 # store the user who made the change | ||
t.string :action, :limit=>6 # store the change action: create, read, update, delete | ||
t.text :old_value # the value before change | ||
t.text :new_value # value after change | ||
t.string :field_type, :limit=>30 # the column type eg. date, text, varchar, int etc | ||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :change_log | ||
end | ||
end | ||
</code></pre> | ||
|
||
Then: | ||
<pre><code>rake db:migrate</code></pre> | ||
|
||
h2. Use Change Log | ||
1. Add current_user method in application_controller.rb | ||
<pre><code> | ||
# used by change log | ||
def current_user # :nodoc: | ||
return session[:user] # replace this with your own code to tell change_log who is the current user | ||
end | ||
</code></pre> | ||
|
||
h2. Testing | ||
TODO:: | ||
|
||
|
||
Author | ||
------ | ||
|
||
Peter Zhang at NCS New Zealand. | ||
Email: peterz@ncs.co.nz | ||
Description: Keep recording every changes did by user | ||
|
||
Copyright (c) 2011 Peter Zhang, released under the MIT license |