我看过很多关于这个的帖子,但似乎没有一个能解决我的问题。我有一个 default_scope
在这样的模型上:
default_scope where(:is_active => true).order('LOWER(table.name)');
我有其他(普通)范围,我想创建一个
inactive
范围使用 unscoped
.我想将它定义为一个范围,但它仅在定义为类方法时才有效:# works
def self.inactive
unscoped { where(:is_active => false) }
end
# none of these work
scope :inactive, unscoped { where(:is_active => false) }
scope :inactive, with_exclusive_scope { where(:is_active => true) }
scope :inactive, unscoped.where(:is_active => false)
scope :inactive, lambda { unscoped { where(:is_active => false) } }
scope :inactive, unscoped { lambda { where(:is_active => false) } }
unscoped do
scope :inactive, where(:is_active => false)
end
有没有我错过的方法,或者我是否必须使用类方法来定义这个范围?
最佳答案
似乎没有办法做到这一点。我在 github 上的 rails repo 上打开了一个问题......
关于ruby-on-rails - Rails 3.1.3 无作用域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8734669/