Cbas Cbas - 2 years ago 86
Ruby Question

ILIKE search on full name only works on first name?

I have a

table with a
field which contains the users full name.

I wrote a search function that should allow finding users by their first name or their last name, but it only returns results for first names.

For example if I have a user: = 'John Smith'
, if I enter 'John' I get the record back, but if I enter 'Smith' I get no results. Here's my search code:

name_users = User.where('name ILIKE ?', params["search_text"] + '%').all

How can I allow searching by last name?

dkp dkp
Answer Source

Try this:

name_users = User.where('name ILIKE ?', "%#{params["search_text"]}%")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download