I'm looking to do a query for an activity object in my app. I'm using the public_activity
gem and I have a list of activities which are connected to several models and I would like to list out the most recent unique activity.
Basically I would like to query the most recent activity for a particular tracking. Let's say that I'm tracking the like button and it's ID
is 29
. I want to query out the most recent (one) instance of tracking ID=29
and other tracking IDs. I don't know the querying for rails too well. Right now this is the only line I have which displays all activity:
@activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.id)
Let's say I have a table of activities as follows:
id activity_id description created_on
1 3 Like yesterday
2 3 Unlike two days ago
3 6 Comment yesterday
4 7 Review yesterday
5 7 Review two days ago
I want to pull out the most recent entries of each activity ID into the @activities
variable like the following:
id activity_id description created_on
1 3 Like yesterday
3 6 Comment yesterday
4 7 Review yesterday
Does public_activity
have a workaround for this?