2

我试图让基于 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
4

1 回答 1

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
...
于 2013-05-12T02:42:33.050 回答