Module: UserSearchConcern::ClassMethods

Defined in:
app/models/concerns/user_search_concern.rb

Instance Method Summary collapse

Instance Method Details

#search(keyword) ⇒ Array<User>

Search and filter users by their names or emails.


11
12
13
14
15
16
17
18
# File 'app/models/concerns/user_search_concern.rb', line 11

def search(keyword)
  return all if keyword.blank?

  condition = "%#{keyword}%"
  joining { emails.outer }.
    where.has { (name =~ condition) | (emails.email =~ condition) }.
    group('users.id')
end