Here’s a solution I’ve used on a project to add a user switcher dropdown with typeahead search to a navbar. It uses the pg_search gem for Postgres full-text search.
There are a lot of blog posts out there with similar solutions, with terms like: typeahead, autocomplete, autosuggest, instant search.
class User < ApplicationRecord include PgSearch::Model pg_search_scope( :user_search, against: { first_name: "A", last_name: "A" }, using: { tsearch: { prefix: true, dictionary: "english" } } ) def full_name [first_name, last_name].compact_blank.join(" ") end end