Ahmed Reza
Ahmed Reza

Reputation: 293

How to show activity only to a specific user in Public activity gem

What am trying to do is to use public activity gem to build a notification system i followed this Railscast and everything worked just fine.

I have a article and a comment model where users can comment on each others article and the user whom the article belongs to will get notified in their activity feed, but the problem here is that the activity page shows activity of all users, but now i want to show activity only to the specific person whom the article belongs to. So if a user clicks on the activity button they will only see the activities that happened on there article.

Is there any way to accomplish that ?

Upvotes: 1

Views: 213

Answers (1)

Linus Oleander
Linus Oleander

Reputation: 18127

If the owner is set in the model, like this

class Comment < ActiveRecord::Base
  include PublicActivity::Model
  tracked owner: Proc.new{ |controller, model| controller.current_user }
end

then you can use a regular where clause to fetch the data.

PublicActivity::Activity.where("owner_id = ?", user.id)

Upvotes: 1

Related Questions