2

although i had asked this question before but didn't get any useful answer

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. Means 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 ? Thanks in advance.

what i had tried till now, but it doesn't seems to work

activities_controller.rb

class ActivitiesController < ApplicationController
 def index
   @activities = PublicActivity::Activity.all.order("created_at desc")
                  .where(trackable_type: "Comment", owner_id: current_user.id, owner_type: "User")
 end
end
Ahmed Reza
  • 293
  • 1
  • 3
  • 19

1 Answers1

1

Please set the recipient of your activities something like this (assuming your comment model belongs_to article model):

racked recipient: ->(controller, model) { model && model.article.user }

You might find this useful: How to set up the recipient id in public activity

Now fetch your activities if current_user is the recipient:

PublicActivity::Activity.order('created_at desc')
                  .where(recipient_id: current_user.id)
                  .where('owner_id not in (?)', current_user.id)
                  .where(trackable_type: "Comment",  owner_type: "User")
                  .all
Community
  • 1
  • 1
sonalkr132
  • 967
  • 1
  • 9
  • 25