Jonah Katz
Jonah Katz

Reputation: 5298

Search accorss multiple columns?

I followed a railcast to search a single column from a database, which worked fine. Im trying to tweak it to search across multiple columns (first_name AND last_name), but its only searching across last_name , im new to rails, so i feel like i have a simply syntax error (does || or?) Any suggestions? Here's my code.

 where('first_name || last_name LIKE ?', "%#{search}%")

Upvotes: 0

Views: 507

Answers (1)

user517491
user517491

Reputation:

where('first_name LIKE ? || last_name LIKE ?', "%#{search}%" , "%#{search}%")

Upvotes: 2

Related Questions