I
I
IvanN7772014-11-19 19:03:51
Ruby on Rails
IvanN777, 2014-11-19 19:03:51

How to properly remove users in the rails model (with a tick disabled)?

I have a Users model
in the users table, there is an access field
that has the values ​​\u200b\u200b(true, false)
Is it possible to cut off users who have false at the model level
Or do I need to register where (xxx, access = true) everywhere

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2014-11-19
@IvanN777

class User < ActiveRecord::Base
default_scope ->{ where(access: true) }
...
end

And all users will be selected by default only with true
And if all are needed, then:
But in general, the default scope is not a good thing. It's better to make a normal named scope:
class User < ActiveRecord::Base
scope :with_access, -> { where(access: true) }
...
end

And call like:
User.with_access

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question