public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Added activities to blog comments the Right Way (TM)
Michael Hartl (author)
Fri Mar 28 17:39:58 -0700 2008
commit  5e144434f6150259083398fffd3d01911cabf36d
tree    5c702faa05a96bca6d2252f2b80998f7a57aa97b
parent  f1509d18db74efd28fdedfd33a72fda09ee0c1df
...
16
17
18
19
20
21
22
...
34
35
36
37
 
38
39
...
16
17
18
 
19
20
21
...
33
34
35
 
36
37
38
0
@@ -16,7 +16,6 @@
0
 #
0
 
0
 class BlogPost < Post
0
- include ActivityLogger
0
   
0
   MAX_TITLE = SMALL_STRING_LENGTH
0
   MAX_BODY = MEDIUM_TEXT_LENGTH
0
@@ -34,6 +33,6 @@ class BlogPost < Post
0
   private
0
   
0
     def log_activity
0
- add_activities(self, blog.person)
0
+ add_activities(:item => self, :person => blog.person)
0
     end
0
 end
...
13
14
15
16
 
17
18
19
...
27
28
29
30
31
32
33
34
35
36
 
 
37
38
...
13
14
15
 
16
17
18
19
...
27
28
29
 
 
 
 
 
 
 
30
31
32
33
0
@@ -13,7 +13,7 @@
0
 # updated_at :datetime
0
 #
0
 
0
-class BlogPostComment < Comment
0
+class BlogPostComment < Comment
0
   belongs_to :commenter, :class_name => "Person",
0
                          :foreign_key => "commenter_id"
0
   belongs_to :post, :counter_cache => true, :foreign_key => "blog_post_id"
0
@@ -27,12 +27,7 @@ class BlogPostComment < Comment
0
   
0
     def log_activity
0
       activity = Activity.create!(:item => self, :person => commenter)
0
- add_activities(post.blog.person, activity)
0
- add_activities(commenter, activity)
0
- end
0
-
0
- def add_activities(person, activity)
0
- person.activities << activity
0
- person.contacts.each { |c| c.activities << activity }
0
+ add_activities(:activity => activity, :person => post.blog.person)
0
+ add_activities(:activity => activity, :person => commenter)
0
     end
0
 end
...
14
15
16
 
17
18
...
14
15
16
17
18
19
0
@@ -14,5 +14,6 @@
0
 #
0
 
0
 class Comment < ActiveRecord::Base
0
+ include ActivityLogger
0
   validates_presence_of :body
0
 end
...
16
17
18
19
20
21
22
...
29
30
31
32
 
33
34
...
16
17
18
 
19
20
21
...
28
29
30
 
31
32
33
0
@@ -16,7 +16,6 @@
0
 #
0
 
0
 class ForumPost < Post
0
- include ActivityLogger
0
   
0
   belongs_to :topic, :counter_cache => true
0
   belongs_to :person, :counter_cache => true
0
@@ -29,6 +28,6 @@ class ForumPost < Post
0
   private
0
   
0
     def log_activity
0
- add_activities(self, person)
0
+ add_activities(:item => self, :person => person)
0
     end
0
 end
...
16
17
18
 
19
...
16
17
18
19
20
0
@@ -16,4 +16,5 @@
0
 #
0
 
0
 class Post < ActiveRecord::Base
0
+ include ActivityLogger
0
 end
...
1
2
3
 
 
 
 
4
5
6
...
1
 
 
2
3
4
5
6
7
8
0
@@ -1,6 +1,8 @@
0
 module ActivityLogger
0
- def add_activities(item, person)
0
- activity = Activity.create!(:item => item, :person => person)
0
+ def add_activities(options = {})
0
+ person = options[:person]
0
+ activity = options[:activity] ||
0
+ Activity.create!(:item => options[:item], :person => person)
0
     person.activities << activity
0
     person.contacts.each { |c| c.activities << activity }
0
   end

Comments

    No one has commented yet.