I’m fetching all the users by this now.
However, I want to exclude non-confirmed users.
Their confirmed_at attribute is nil.
How can I?
@search = User.search do
fulltext params[:search]
paginate :page => params[:page], :per_page => 10
end
@users = @search.results
First add a scope to your User model:
Then you have just to add the scope before the search
EDIT:
Indeed, after a test, the solution above don’t seem to work. The scope seems to be ignored. There’s another solution:
In your
Usermodel you probably have a method like this:You have to add a condition to
searchable:EDIT 2:
There is another way if sometimes you want confirmed users and sometimes all users, but you need to modify you model too.
In you
Usermodel:Then in your controller
I hope this help