linkingpaths / acts_as_scribe
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
9270083
acts_as_scribe / README.markdown
| d1841f9c » | aitor | 2008-09-09 | 1 | ActsAsScribe | |
| 6bd9ae7c » | aitor | 2008-09-09 | 2 | ============ | |
| d1841f9c » | aitor | 2008-09-09 | 3 | A simple plugin that allows to keep history records of the users activities. Common uses could be user's wall, public timeline portlets, etc... | |
| 4 | |||||
| 6bd9ae7c » | aitor | 2008-09-09 | 5 | > Scribe (From Wikipedia, the free encyclopedia): | |
| d1841f9c » | aitor | 2008-09-09 | 6 | "A scribe was traditionally a person who could read and write. This usually indicated secretarial and administrative duties such as dictation and keeping business, judicial, and history records for kings, nobles, temples, and cities." | |
| 7 | |||||
| a2833f0b » | aitor | 2008-09-09 | 8 | Resources | |
| 6bd9ae7c » | aitor | 2008-09-09 | 9 | ========= | |
| d1841f9c » | aitor | 2008-09-09 | 10 | ||
| 11 | Install | ||||
| 6bd9ae7c » | aitor | 2008-09-09 | 12 | ------- | |
| d1841f9c » | aitor | 2008-09-09 | 13 | ||
| 14 | * Run the following command: | ||||
| 15 | |||||
| a2833f0b » | aitor | 2008-09-09 | 16 | `script/plugin install git://github.com/linkingpaths/acts_as_scribe.git` | |
| d1841f9c » | aitor | 2008-09-09 | 17 | ||
| 18 | * Generate the tables via the given generator: | ||||
| 19 | |||||
| a2833f0b » | aitor | 2008-09-09 | 20 | `script/generate acts_as_scribe_migration` | |
| d1841f9c » | aitor | 2008-09-09 | 21 | ||
| 22 | * And finally... | ||||
| 23 | |||||
| a2833f0b » | aitor | 2008-09-09 | 24 | `rake db:migrate` | |
| d1841f9c » | aitor | 2008-09-09 | 25 | ||
| 519713f5 » | aitor | 2009-02-24 | 26 | Record activities in your models | |
| 27 | --------------------------------------------- | ||||
| d1841f9c » | aitor | 2008-09-09 | 28 | ||
| a2833f0b » | aitor | 2008-09-09 | 29 | <pre> | |
| d1841f9c » | aitor | 2008-09-09 | 30 | class Comment < ActiveRecord::Base | |
| ffc49443 » | aitor | 2008-09-16 | 31 | record_activity_of :user | |
| d1841f9c » | aitor | 2008-09-09 | 32 | end | |
| a2833f0b » | aitor | 2008-09-09 | 33 | </pre> | |
| 519713f5 » | aitor | 2009-02-24 | 34 | You can use any association that is related to an user: | |
| 35 | <pre> | ||||
| 36 | class Post < ActiveRecord::Base | ||||
| 37 | belongs_to :author, :class_name => "User" | ||||
| 38 | record_activity_of :author | ||||
| 39 | end | ||||
| 40 | </pre> | ||||
| 41 | |||||
| 42 | This will register automatically a new activity when you create or destroy a new record. If you want control over the activities registration based on your model's state just use the :if option | ||||
| 5d1c49aa » | aitor | 2008-09-16 | 43 | ||
| 44 | <pre> | ||||
| 519713f5 » | aitor | 2009-02-24 | 45 | class Post < ActiveRecord::Base | |
| 46 | belongs_to :author, :class_name => "User" | ||||
| 47 | record_activity_of :author, :if => Proc.new { |post| post.private == false } | ||||
| 48 | end | ||||
| 49 | </pre> | ||||
| 50 | |||||
| 51 | |||||
| 52 | Record activities without related item | ||||
| 53 | -------------------------------------- | ||||
| 54 | |||||
| 55 | If you want to record activities not related to any specific model just use `Activity.report` in your code: | ||||
| 56 | <pre> | ||||
| 57 | def grant_admin(user) | ||||
| 58 | user.admin = true | ||||
| 59 | Activity.report(current_user, :grant_admin, user) | ||||
| 60 | end | ||||
| 61 | </pre> | ||||
| 62 | If the action is not related to any item, just don't use it. | ||||
| 63 | <pre> | ||||
| 64 | def login | ||||
| 65 | current_user = User.find(…) | ||||
| 66 | Activity.report(current_user, :login) | ||||
| 5d1c49aa » | aitor | 2008-09-16 | 67 | end | |
| 68 | </pre> | ||||
| d1841f9c » | aitor | 2008-09-09 | 69 | ||
| 70 | |||||
| 71 | |||||
| 6bd9ae7c » | aitor | 2008-09-09 | 72 | More | |
| 73 | ------- | ||||
| a2833f0b » | aitor | 2008-09-09 | 74 | ||
| 75 | [http://github.com/linkingpaths/acts\_as\_scribe](http://github.com/linkingpaths/acts_as_scribe) | ||||
| 76 | |||||
| 77 | [http://github.com/linkingpaths/acts\_as\_scribe/wikis](http://github.com/linkingpaths/acts_as_scribe/wikis) | ||||
| d1841f9c » | aitor | 2008-09-09 | 78 | ||
| 79 | |||||
| 80 | Copyright (c) 2008 Linking Paths, released under the MIT license | ||||

