在我的 Activity 模型中,我有一个默认范围:
default_scope where(:subject_id => Log.get_subject_id)
问题出在 Log.get_subject_id 中,默认值为 0。这是我的 Log 模型:
@@subject_id = 0
def self.set_subject_id(val)
@@subject_id = val
end
def self.get_subject_id
@@subject_id
end
当我通过控制器中的 Log.set_subject_id(10) 更改 @@subject_id 的值然后我尝试 Activity.all 时,它总是给我不好的结果。SQL:
SELECT "activities".* FROM "activities" WHERE "activities"."subject_id" = 0
哪里有问题?谢谢!