Im beginner in rails and have some problems to improve my search query:
In the controller i call:
def index
if params[:search]
@persons = Person.search(params[:search]).order("created_at DESC")
else
@persons = Person.order("created_at DESC")
end
end
And in the model i have:
def self.search(query)
where("name like ?", "%#{query}%")
end
So actually i only filter name! Now i tried to improve it but it didnt worked out how i liked it, my aim is that a user can type in for example:
John
Smith
Smith John
John Smith
and it always should return John Smith
. So how do i write such a long sql query? Thanks in advance!