【发布时间】:2011-05-05 05:07:23
【问题描述】:
我正在使用timeline_fu plugin。我想过滤recent_events,以便与当前用户有关的任何事件都不是recent_event。更具体地说,如果用户对视频进行投票,并且该视频属于当前用户,我不希望它成为 current_user 的 recent_event。就我而言,这意味着当secondary_object.user == current_user 时,我不希望包含recent_event。 (我将视频设置为secondary_object)。我不确定在哪里以及如何构建这个逻辑。
这是创建 recent_events 关联并通过 RECENT_EVENTS_CONDITIONS 过滤它们的代码(它基本上是在事件的参与者是当前用户关注的用户时过滤它们)
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'
我可以把它放在 SQL 片段或 has_many 关联的:conditions 选项中吗?
或者我可以将它放在timeline_fu 插件为创建事件提供的:if => 选项中。然而,这并不理想,因为我在这里无法访问current_user。我该如何做到这一点?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 feed timeline