0

I have a model with a default scope:

default_scope -> { where(is_active: true) }

Can I unscope the model in Administrate, so the I can see all the records in the admin panel?

pmichna
  • 4,800
  • 13
  • 53
  • 90
  • duplicate ? http://stackoverflow.com/questions/1648971/rails-why-is-with-exclusive-scope-protected-any-good-practice-on-how-to-use-it – fanta Jan 13 '17 at 19:48
  • I don't think it's a duplicate of that specific answer. – Ryenski Jan 13 '17 at 19:55

2 Answers2

0

You can unscope the where clause using the unscope method. Here's how you'd create a new scope overriding the where clause in default_scope.

scope :including_inactive, ->{ unscope(where: :is_active) }
Ryenski
  • 9,582
  • 3
  • 43
  • 47
0

You could do:

User.unscope(where: :is_active)

but it would probably be better to just not have a default scope if you are not going to use it everywhere.

link

Timmy Von Heiss
  • 2,160
  • 17
  • 39