0

i have used public_activity gem in my app and also the act_as_follower gem where a user can follow other user

the logic i am using to fetch all the following activities is

@follow_activities = PublicActivity::Activity.where(trackable_type: 'follow', key: 'follow.create')

here @follow_activities is fetching all the records where the following has been done but i want to limit this query, It should fetch the follow activities only of those users which the current_user has followed.

fetching all queries is a bad idea.

for elaboration i am showing you the models i have included

class User< ActiveRecord::Base

acts_as_follower
acts_as_followable

end

and the follow model is as

  class Follow < ActiveRecord::Base
      include PublicActivity::Model
      tracked owner: ->(controller, model) { controller && controller.current_user }
      extend ActsAsFollower::FollowerLib
      extend ActsAsFollower::FollowScopes

      # NOTE: Follows belong to the "followable" interface, and also to followers
      belongs_to :followable, :polymorphic => true
      belongs_to :follower,   :polymorphic => true

      def block!
        self.update_attribute(:blocked, true)
      end

    end

Please tell me how can i limit the records fetching. Thankx in advance

user4965201
  • 973
  • 1
  • 11
  • 25

1 Answers1

0

I finally figured it out i need to do this

follow_activities = PublicActivity::Activity.where(trackable_type: 'follow', key: 'follow.create', owner_id: current_user.all_following)

now this will fetch the records of only those users which the current_user has followed

user4965201
  • 973
  • 1
  • 11
  • 25