parm530
12/4/2018 - 5:12 PM

Search Bar with Multiple Parameter Options

Searching your database with different kinds of terms

# If your search bar accepts different types of entries
# like numbers, os strings of text to query your database:

# Create a scope method:
scope :search, (search_term) -> { where("LOWER(db_field_name) = LOWER(?) OR LOWER(db_field_name_2)
 LIKE LOWER(?)", search_term, "%#{search_term}%") }
 
 # The LOWER method is used for setting the term to lower case to avoid case sensitivity