将 public_activity 与acts_as_follower 和devise 一起使用,如何仅显示用户的活动和他关注的人的活动? [英] Using public_activity with acts_as_follower and devise, how can I show only the user's activities and those of the people he follows?
问题描述
我正在尝试让基于 public_activity gem 的通知控制器显示用户的活动以及他关注的用户的活动.
I am trying to get my notifications controller, which is based around the public_activity gem, to show the user's activities in addition to the activities of those he follows.
我正在努力显示用户关注的活动,但我似乎无法将用户自己的活动包括在内.
I have it working to show the activities of those the user follows, but I can't seem to get the user's own activities to be included.
换句话说,这是有效的:
In other words, this works:
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
推荐答案
事实证明 notify_user_of = current_user.following_users
不是我想象的数组,而是一个活动记录对象.通过手动创建数组并向其中添加个人用户,我能够达到预期的结果.
It turns out that notify_user_of = current_user.following_users
was not an array as I had thought, but an active record object. By manually creating the array and adding individual users to it I was able to achieve the desired result.
...
notify_user_of = []
notify_user_of << current_user
for user in current_user.following_users
notify_user_of << user
end
...
这篇关于将 public_activity 与acts_as_follower 和devise 一起使用,如何仅显示用户的活动和他关注的人的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!