我有一个类方法,我想修改当前由ActiveRecord :: Relation对象抓取的记录.但我不知道如何在类方法中引用当前作用域.自我不这样做.
例:
class User < ActiveRecord::Base ... def self.modify_those_records #thought implicitly #to_a would be called on currently grabbed records but doesn't work temp_users_to_a = to_a ... end end
我会像这样使用它:
User.some_scope.modify_those_records
所以User.some_scope会给我一个包含一堆用户记录的ActiveRecord :: Relation.然后,我想修改该类方法中的那些记录,然后返回它们.
问题是:我不知道如何在类方法中明确引用“那组记录”.