我正在尝试获取基于public_activity gem的通知控制器,以显示用户的活动以及他所遵循的活动。
我正在努力展示用户遵循的活动,但我似乎无法将用户自己的活动纳入其中。
换句话说,这有效:
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
答案 0 :(得分:1)
事实证明notify_user_of = current_user.following_users
不是我想象的数组,而是一个活跃的记录对象。通过手动创建阵列并向其添加单个用户,我能够实现所需的结果。
...
notify_user_of = []
notify_user_of << current_user
for user in current_user.following_users
notify_user_of << user
end
...