2
我試圖讓我的通知控制器(基於public_activity gem)來顯示用戶的活動以及他所關注的活動。使用public_activity與acts_as_follower和設計,我如何只顯示用戶的活動和他關注的人的活動?
我有它的工作,以顯示用戶的活動,但我似乎無法得到用戶自己的活動包括在內。
換句話說,這個工程:
class NotificationsController < CooperativeController
before_filter :authenticate_user!
def index
@activities = PublicActivity::Activity.where(:owner_id => current_user.following_users, :owner_type => 'User').order('created_at DESC')
end
end
雖然這並不:
class NotificationsController < CooperativeController
before_filter :authenticate_user!
def index
notify_user_of = current_user.following_users
notify_user_of << current_user
@activities = PublicActivity::Activity.where(:owner_id => notify_user_of, :owner_type => 'User').order('created_at DESC')
end
end
謝謝,凱倫......現在試圖解決類似的問題。恐怕你的解決方案可能不能很好地擴展 - 我很好奇聽到它最終如何表現。我希望@activities不僅包含用戶所關注人員的那些內容,還包括那些影響用戶對象的人員。因此,如果有人對我的帖子發表評論,即使我沒有關注此人,我也會看到通知。 – 2014-04-01 16:46:16