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
Methods for the stuff on the home page
Michael Hartl (author)
Sun Mar 23 14:59:14 -0700 2008
commit  f2df17d908f59d54add040edfd36c6d93aad7130
tree    11711054699b4fdabf72f7091b9564f02dbd820e
parent  1605776116d48ddfbeba4ab2d3e8e9c2d07d1e97
...
6
7
8
9
10
11
12
13
14
15
16
17
 
 
 
 
 
18
19
20
...
6
7
8
 
 
 
 
 
 
 
 
 
9
10
11
12
13
14
15
16
0
@@ -6,15 +6,11 @@ class HomeController < ApplicationController
0
     
0
     @feed = current_person.feed
0
     
0
- @topics = Topic.find(:all, :order => "created_at DESC", :limit => 6)
0
- @members = Person.find(:all, :order => "people.created_at DESC",
0
- :include => :photos, :limit => 8)
0
- @contacts = current_person.contacts[(0...11)]
0
- @requested_contacts = current_person.requested_contacts[(0...8)]
0
- @requested_contact_links = @requested_contacts.map do |p|
0
- conn = Connection.conn(current_person, p)
0
- edit_connection_path(conn)
0
- end
0
+ @topics = Topic.find_recent
0
+ @members = Person.find_recent
0
+ @contacts = current_person.some_contacts
0
+ @requested_contacts = current_person.requested_contacts
0
+
0
     respond_to do |format|
0
       format.html
0
     end
...
1
 
 
 
 
 
 
2
...
1
2
3
4
5
6
7
8
0
@@ -1,2 +1,8 @@
0
 module CommunicationsHelper
0
+ def contact_links(requested_contacts)
0
+ requested_contacts.map do |contact|
0
+ conn = Connection.conn(current_person, contact)
0
+ edit_connection_path(conn)
0
+ end
0
+ end
0
 end
...
38
39
40
 
41
42
43
...
45
46
47
48
 
49
50
51
52
 
 
53
54
55
...
79
80
81
82
83
84
85
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
 
 
92
93
94
...
99
100
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
103
104
...
38
39
40
41
42
43
44
...
46
47
48
 
49
50
51
 
 
52
53
54
55
56
...
80
81
82
 
 
 
 
 
 
 
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
99
100
101
102
103
...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
0
@@ -38,6 +38,7 @@ class Person < ActiveRecord::Base
0
   MESSAGES_PER_PAGE = 5
0
   NUM_RECENT_MESSAGES = 4
0
   NUM_WALL_COMMENTS = 10
0
+ NUM_RECENT = 8
0
   FEED_SIZE = 10
0
 
0
   has_one :blog
0
@@ -45,11 +46,11 @@ class Person < ActiveRecord::Base
0
                       :order => "created_at DESC", :limit => NUM_WALL_COMMENTS
0
   has_many :connections
0
   has_many :contacts, :through => :connections,
0
- :conditions => "status = #{Connection::ACCEPTED}"
0
+ :conditions => "status = #{Connection::ACCEPTED}"
0
   has_many :photos, :dependent => :destroy, :order => 'created_at'
0
   has_many :requested_contacts, :through => :connections,
0
- :source => :contact,
0
- :conditions => "status = #{Connection::REQUESTED}"
0
+ :source => :contact,
0
+ :conditions => "status = #{Connection::REQUESTED}"
0
   with_options :class_name => "Message", :dependent => :destroy,
0
                :order => 'created_at DESC' do |person|
0
     person.has_many :_sent_messages, :foreign_key => "sender_id",
0
@@ -79,16 +80,24 @@ class Person < ActiveRecord::Base
0
   
0
   ## Class methods
0
   
0
- # People search using Ferret
0
- def self.search(query, options = {})
0
- return [].paginate if query.blank?
0
- limit = [total_hits(query), SEARCH_LIMIT].min
0
- paginate_by_contents(query, :page => options[:page],
0
- :per_page => SEARCH_PER_PAGE,
0
- :total_entries => limit)
0
+ class << self
0
+ # People search using Ferret
0
+ def search(query, options = {})
0
+ return [].paginate if query.blank?
0
+ limit = [total_hits(query), SEARCH_LIMIT].min
0
+ paginate_by_contents(query, :page => options[:page],
0
+ :per_page => SEARCH_PER_PAGE,
0
+ :total_entries => limit)
0
+ end
0
+
0
+ def find_recent
0
+ find(:all, :order => "people.created_at DESC",
0
+ :include => :photos, :limit => NUM_RECENT)
0
+ end
0
   end
0
   
0
- ## Feed
0
+
0
+ ## Feeds
0
   
0
   def feed
0
     events
0
@@ -99,6 +108,20 @@ class Person < ActiveRecord::Base
0
                                       :limit => FEED_SIZE)
0
   end
0
   
0
+ ## For the home page...
0
+
0
+ # Return some contacts for the home page.
0
+ def some_contacts
0
+ contacts.shuffle[(0...12)]
0
+ end
0
+
0
+ def requested_contact_links
0
+ requested_contacts.map do |p|
0
+ conn = Connection.conn(self, p)
0
+ edit_connection_path(conn)
0
+ end
0
+ end
0
+
0
   ## Message methods
0
 
0
   def received_messages(page = 1)
...
15
16
17
 
18
19
20
...
26
27
28
 
 
 
 
29
30
31
...
15
16
17
18
19
20
21
...
27
28
29
30
31
32
33
34
35
36
0
@@ -15,6 +15,7 @@
0
 class Topic < ActiveRecord::Base
0
   
0
   MAX_NAME = MEDIUM_STRING_LENGTH
0
+ NUM_RECENT = 6
0
   
0
   belongs_to :forum, :counter_cache => true
0
   belongs_to :person
0
@@ -26,6 +27,10 @@ class Topic < ActiveRecord::Base
0
   
0
   after_create :log_event
0
   
0
+ def self.find_recent
0
+ find(:all, :order => "created_at DESC", :limit => NUM_RECENT)
0
+ end
0
+
0
   private
0
   
0
     def log_event
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,5 +1,5 @@
0
 <%- unless current_person.requested_contacts.empty? -%>
0
 <%= raster image_links(@requested_contacts,
0
- :links => @requested_contact_links),
0
+ :links => contact_links(@requested_contacts)),
0
            :title => "Requested Connections" %>
0
 <%- end -%>
0
\ No newline at end of file

Comments

    No one has commented yet.