TheBreeze / shadow

Provides a history of attribute and association updates for models. This coincides with a versioning system (such as acts_as_versioned). When used in tandem, you get both a history of changes and a history of what changed.

This URL has Read+Write access

shadow / README.markdown
26dea2fa » TheBreeze 2008-05-02 Initial import of shadow. Comment 1 Shadow
2 ======
3
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 4 Provides a history of attribute and association updates for models. This coincides with a versioning system (such as acts_as_versioned). When used in tandem, you get both a history of changes and a history of what changed.
26dea2fa » TheBreeze 2008-05-02 Initial import of shadow. Comment 5
6a929120 » TheBreeze 2008-05-30 Updated README with Install... 6 Installation
7 ============
8
2b5a2117 » TheBreeze 2008-09-19 9 If you are running Rails 2.1 or later, installation is straightforward:
6a929120 » TheBreeze 2008-05-30 Updated README with Install... 10
11 <pre><code>
12 $ ./script/plugin install git://github.com/TheBreeze/shadow.git
13 </code></pre>
14
15 Otherwise, the process is a bit more involved, see below:
16
17 <pre><code>
18 $ cd /path/to/your/rails/app
19 $ git clone --depth 1 git://github.com/TheBreeze/shadow.git "./vendor/plugins/shadow/"; rm -rf ./vendor/plugins/shadow/.git
20 </code></pre>
21
22
26dea2fa » TheBreeze 2008-05-02 Initial import of shadow. Comment 23 Example
24 =======
25
72739672 » TheBreeze 2008-05-02 Final changes to README. 26 <pre><code>
27 # After creating your migrations (see TODO)
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 28
72739672 » TheBreeze 2008-05-02 Final changes to README. 29 # In your model
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 30
b260b1c1 » TheBreeze 2008-05-02 Updated README content 31 class Vacation < ActiveRecord::Base
32 has_many :photos
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 33
b260b1c1 » TheBreeze 2008-05-02 Updated README content 34 # By default, shadows all :attributes and :associations. Here we're attaching a user, so we know who added a photo.
35 shadow :associations => :photos, :attach => :user
36 end
5ef5d6e8 » TheBreeze 2008-05-02 Using pre and code tags. 37 </code></pre>
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 38
5ef5d6e8 » TheBreeze 2008-05-02 Using pre and code tags. 39 <pre><code>
72739672 » TheBreeze 2008-05-02 Final changes to README. 40 # In your controller (here we assume nested under VacationController)
41
b260b1c1 » TheBreeze 2008-05-02 Updated README content 42 class PhotosController < ApplicationController
43 def create
44 @vacation = Vacation.find params[:vacation_id]
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 45
b260b1c1 » TheBreeze 2008-05-02 Updated README content 46 # This is where you attach the :user to the photo. If Photo doesn't have a user attribute or association, shadow
47 # will attach an attr_accessor to it and store it with the AssociationShadow record.
48 @photo = Photo.new params[:photo].merge(:user => current_user)
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 49
b260b1c1 » TheBreeze 2008-05-02 Updated README content 50 # You must either use the #association<<, #association.push, or #association.create for the shadow to be created.
51 if @vacation.photos << @photo
52 # success!
53 end
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 54 end
55 end
5ef5d6e8 » TheBreeze 2008-05-02 Using pre and code tags. 56 </code></pre>
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 57
72739672 » TheBreeze 2008-05-02 Final changes to README. 58 <pre><code>
59 # In your view (displaying the updates in the show action of VacationController)
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 60
72739672 » TheBreeze 2008-05-02 Final changes to README. 61 &lt;h1&gt;Vacation Updates&lt;/h1&gt;
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 62
6d0ac940 » TheBreeze 2008-05-02 lt and gt. 63 &lt;% @vacation.association_updates.each do |update| -%&gt;
64 &lt;p&gt;&lt;%= update.user.name %&gt; &lt;%= update.action %&gt; &lt;%= update.record.thumbnail %&gt; to &lt;%= update.association %&gt;&lt;/p&gt;
65 &lt;% end -%&gt;
5ef5d6e8 » TheBreeze 2008-05-02 Using pre and code tags. 66 </code></pre>
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 67
68
72739672 » TheBreeze 2008-05-02 Final changes to README. 69 <pre><code>
70 # Example result from view:
71
39959b57 » TheBreeze 2008-05-02 lt and gt. 72 &lt;h1&gt;Vacation Updates&lt;/h1&gt;
73 &lt;p&gt;Jordan added [photo thumbnail] to photos&lt;/p&gt;
72739672 » TheBreeze 2008-05-02 Final changes to README. 74 </code></pre>
cc528304 » TheBreeze 2008-05-02 Updated README, added TODO,... 75
1d59792c » TheBreeze 2008-05-02 Updated copyright. 76 Copyright (c) 2008 Jordan Fowler, released under the MIT license, and originally developed for Cinema Treasures, LLC (http://www.cinematreasures.org/).