
Untitled
By: a guest on
Apr 29th, 2012 | syntax:
None | size: 1.00 KB | hits: 12 | expires: Never
How do I make a newsfeed without many join statements
@user = current_user # (?)
recent_since = 24.hours.ago
@news_feed = []
# 1) I want my newsfeed to include when public projects are created.
@news_feed += Project.recent.open
# 2) When you are invited to a private project.
@news_feed += @user.invites.received.pending
# 3) When a user follows a project.
@news_feed += @user.user_following_relationships.recent
# 4) And then all of the actions of the other users that you're following.
@news_feed += @user.follows.collect(&:activities)
# 5) Then for the private projects I have another join table to determine who has access to the projects. (There are also comments on each of these projects that I want to show up in the newsfeed as well).
@news_feed += @user.projects.closed
@news_feed.sort!{ |a,b| a.created_at <=> b.created_at }
scope :recent, :conditions => ["created_at >= ?", 24.hours.ago]
scope :open, :conditions => "publicity = 'Public'"
scope :closed, :conditions => "publicity = 'Private'"