Loren
Loren

Reputation: 3466

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?

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

While this doesn't:

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

Upvotes: 2

Views: 614

Answers (1)

Loren
Loren

Reputation: 3466

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
...

Upvotes: 1

Related Questions