【发布时间】:2012-09-11 07:51:47
【问题描述】:
我在访问范围时收到此错误。
这是AR模型
class StatisticVariable < ActiveRecord::Base
attr_accessible :code, :name
has_many :statistic_values
scope :logins, where(code: 'logins').first
scope :unique_logins, where(code: 'unique_logins').first
scope :registrations, where(code: 'registrations').first
end
当我尝试使用 StatisticVariable.logins 或它提供的任何其他范围时:
NoMethodError: undefined method `default_scoped?'
如果我将作用域配置为类方法,那么它可以完美地工作。
def self.registrations
where(code: 'registrations').first
end
请指导我理解并解决这个问题。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 activerecord named-scope