ruby-on-rails - Rails 3.1.3 无作用域

标签 ruby-on-rails activerecord ruby-on-rails-3.1 default-scope

我看过很多关于这个的帖子,但似乎没有一个能解决我的问题。我有一个 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/

相关文章:

ruby-on-rails - 如何在没有 RVM 的情况下在 Ubuntu 上安装 Ruby 1.9.3?

ruby-on-rails - rails rake 路线他们来自哪里

ruby-on-rails - 获取两个事件记录关系的交集,rails

ruby-on-rails-3.1 - ICS 文件的 Amazon SES 附件错误

laravel - 如何在 Laravel 5 中链接查询

mysql - 避免由于竞争条件导致的超额预订

ruby-on-rails - 在 RoR 的文本字段中设置最大长度

javascript - Ruby on Rails : Validate a user has selected a checkbox

ruby-on-rails - 是否应该在 Cucumber 功能中测试所有验证规则?

ruby-on-rails - Rails 初学者,初始化对象