Sha256: 65b851d3a1119af4b201c698cc2317e365e080266783c2218276594fd6e1f910
Contents?: true
Size: 942 Bytes
Versions: 13
Compression:
Stored size: 942 Bytes
Contents
module Virgo class User < ActiveRecord::Base module Search extend ActiveSupport::Concern included do scope :search, ->(filters=nil) { filters ||= {} items = all if filters[:term].present? parts = filters[:term].split(" ") queries = [] vals = {} parts.each_with_index do |part, i| vals[:"term_#{i}"] = "%#{part}%" queries << \ "(virgo_users.email ILIKE :term_#{i} OR " + "virgo_users.first_name ILIKE :term_#{i} OR " + "virgo_users.last_name ILIKE :term_#{i} OR " + "virgo_users.username ILIKE :term_#{i} OR " + "virgo_users.byline ILIKE :term_#{i})" end query = queries.join(" OR ") items = items.where(query, vals) end items } end end end end
Version data entries
13 entries across 13 versions & 1 rubygems