TheBreeze / shadow
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
ae92c75
shadow / README.markdown
| 26dea2fa » | TheBreeze | 2008-05-02 | 1 | Shadow | |
| 2 | ====== | ||||
| 3 | |||||
| cc528304 » | TheBreeze | 2008-05-02 | 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 | 5 | ||
| 6a929120 » | TheBreeze | 2008-05-30 | 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 | 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 | 23 | Example | |
| 24 | ======= | ||||
| 25 | |||||
| 72739672 » | TheBreeze | 2008-05-02 | 26 | <pre><code> | |
| 27 | # After creating your migrations (see TODO) | ||||
| cc528304 » | TheBreeze | 2008-05-02 | 28 | ||
| 72739672 » | TheBreeze | 2008-05-02 | 29 | # In your model | |
| cc528304 » | TheBreeze | 2008-05-02 | 30 | ||
| b260b1c1 » | TheBreeze | 2008-05-02 | 31 | class Vacation < ActiveRecord::Base | |
| 32 | has_many :photos | ||||
| cc528304 » | TheBreeze | 2008-05-02 | 33 | ||
| b260b1c1 » | TheBreeze | 2008-05-02 | 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 | 37 | </code></pre> | |
| cc528304 » | TheBreeze | 2008-05-02 | 38 | ||
| 5ef5d6e8 » | TheBreeze | 2008-05-02 | 39 | <pre><code> | |
| 72739672 » | TheBreeze | 2008-05-02 | 40 | # In your controller (here we assume nested under VacationController) | |
| 41 | |||||
| b260b1c1 » | TheBreeze | 2008-05-02 | 42 | class PhotosController < ApplicationController | |
| 43 | def create | ||||
| 44 | @vacation = Vacation.find params[:vacation_id] | ||||
| cc528304 » | TheBreeze | 2008-05-02 | 45 | ||
| b260b1c1 » | TheBreeze | 2008-05-02 | 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 | 49 | ||
| b260b1c1 » | TheBreeze | 2008-05-02 | 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 | 54 | end | |
| 55 | end | ||||
| 5ef5d6e8 » | TheBreeze | 2008-05-02 | 56 | </code></pre> | |
| cc528304 » | TheBreeze | 2008-05-02 | 57 | ||
| 72739672 » | TheBreeze | 2008-05-02 | 58 | <pre><code> | |
| 59 | # In your view (displaying the updates in the show action of VacationController) | ||||
| cc528304 » | TheBreeze | 2008-05-02 | 60 | ||
| 72739672 » | TheBreeze | 2008-05-02 | 61 | <h1>Vacation Updates</h1> | |
| cc528304 » | TheBreeze | 2008-05-02 | 62 | ||
| 6d0ac940 » | TheBreeze | 2008-05-02 | 63 | <% @vacation.association_updates.each do |update| -%> | |
| 64 | <p><%= update.user.name %> <%= update.action %> <%= update.record.thumbnail %> to <%= update.association %></p> | ||||
| 65 | <% end -%> | ||||
| 5ef5d6e8 » | TheBreeze | 2008-05-02 | 66 | </code></pre> | |
| cc528304 » | TheBreeze | 2008-05-02 | 67 | ||
| 68 | |||||
| 72739672 » | TheBreeze | 2008-05-02 | 69 | <pre><code> | |
| 70 | # Example result from view: | ||||
| 71 | |||||
| 39959b57 » | TheBreeze | 2008-05-02 | 72 | <h1>Vacation Updates</h1> | |
| 73 | <p>Jordan added [photo thumbnail] to photos</p> | ||||
| 72739672 » | TheBreeze | 2008-05-02 | 74 | </code></pre> | |
| cc528304 » | TheBreeze | 2008-05-02 | 75 | ||
| 1d59792c » | TheBreeze | 2008-05-02 | 76 | Copyright (c) 2008 Jordan Fowler, released under the MIT license, and originally developed for Cinema Treasures, LLC (http://www.cinematreasures.org/). | |

