Answer the question
In order to leave comments, you need to log in
Rails 5, how to fetch database from multiple fields?
The bottom line is this, I make a user search panel on the page, and process the entered values as follows:
users = User.where("first_name LIKE ? or last_name LIKE ?", "%#{params[:search]}%",
"%#{ params[:search]}%") if params[:search].present?
If you search only by first name (first_name) or last name (last_name), then everything works fine, but if you enter the first and last name at once, for example, "Ivan Ivanov", then the search does not work accordingly.
I'm not good at querying the database, can you tell me how to process another option with the entered first name and last name at the same time?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question