ActiveRecord Rails 3 scope vs class method
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to the new query interface of ActiveRecord so I'm still figuring things out. I was hoping someone could explain the difference between using a scope in an ActiveRecord model and just using a class method (ie self.some_method ) From what I can gather, a scope is always expected to return a relation, whereas a class method doesn't necessarily have to. Is this true? For instance, I thought it would make sense to do something like: class Person scope :grouped_counts, group(:name).count end But this doesn't work. I get this error: