【问题标题】:Administrate and unscoping default scope管理和取消范围默认范围
【发布时间】:2017-01-13 19:35:09
【问题描述】:

我有一个具有默认范围的模型:

default_scope -> { where(is_active: true) }

我可以在管理中取消模型的范围,以便我可以在管理面板中查看所有记录吗?

【问题讨论】:

标签: ruby-on-rails rails-administrate


【解决方案1】:

你可以这样做:

User.unscope(where: :is_active)

但如果您不打算在任何地方使用它,最好不要使用默认范围。

link

【讨论】:

    【解决方案2】:

    您可以使用unscope 方法取消where 子句的范围。以下是您如何创建一个覆盖 default_scope 中 where 子句的新范围。

    scope :including_inactive, ->{ unscope(where: :is_active) }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2013-02-19
      相关资源
      最近更新 更多