2017-01-13 53 views
0

我有一个默认范围模型:管理和unscoping默认范围

default_scope -> { where(is_active: true) } 

我可以unscope的管理模型,让我可以看到在管理面板中的所有记录?

+0

duplicate? http://stackoverflow.com/questions/1648971/rails-why-is-with-exclusive-scope-protected-any-good-practice-on-how-to-use-it – fanta

+0

我不认为这是重复的的具体答案。 – mysmallidea

回答

0

你可以这样做:

User.unscope(where: :is_active) 

但它可能会更好,只是没有默认的范围,如果你不打算在任何地方使用它。

link

0

您可以使用unscope方法来查找where子句。以下是如何创建覆盖default_scope中where子句的新范围。

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