I'm using the timeline_fu plugin. I want to filter recent_events
so that any event that has to do with the current user is not a recent_event
. More specifically, if a user votes on a video, and the video belongs to the current user, I do not want it to be a recent_event
for the current_user. In my case, this means that when secondary_object.user == current_user
, I do not want the recent_event
to be included. (I set the video as the secondary_object). I'm unsure of where and how to construct this logic.
This is the code that creates the recent_events
association and filters them by RECENT_EVENTS_CONDITIONS
(it basically filters them for when the actor of the event is a user that is followed by the current user)
RECENT_EVENTS_CONDITION = '(actor_type = \'User\' AND actor_id IN (SELECT followed_id FROM relationships WHERE follower_id = #{id}))'
has_many :recent_events, :class_name => "TimelineEvent",
:finder_sql => 'SELECT timeline_events.* FROM timeline_events
WHERE ' + RECENT_EVENTS_CONDITION + '
ORDER BY timeline_events.created_at DESC'
I could maybe put it in the SQL fragment or in a :conditions
option for the has_many association?
Or I can put it in the :if =>
option that the timeline_fu plugin provides for the creation of events. However this would not be ideal, because I do not have access to current_user
here. How do I accomplish this?
I was able to solve this problem by added an unless
statement in my view. However, I'm unsure if this is the best solution.