我得到错误
undefined local variable or method `id' for #<Class:0x007fe1dc4e3bb0>
在我的模型用户中定义 sql 调用时:
RECENT_EVENTS_CONDITION = "(user_id = #{id}) OR user_id IN (SELECT user_b_id AS user_id FROM user_follows WHERE user_follows.user_a_id = #{id} )"
型号代码
has_many :recent_events,
:class_name => "Activity",
:finder_sql => 'SELECT activities.* FROM activities
WHERE ' + RECENT_EVENTS_CONDITION + '
ORDER BY activities.created_at DESC',
:counter_sql => 'SELECT COUNT(*) FROM activities
WHERE ' + RECENT_EVENTS_CONDITION
一切正常,直到我介绍了这个 recent_events ...