jko170
February 22, 2007, 10:27am
1
My autocomplete method searches only on the last_name column but I’d
like for it to search first_name and last_name for a match. Basically
how gmail and yahoo mail beta does it. I tried the sql OR operator but
I can’t get it to work.
def autocomplete
search = params[:user]
@users = User.find(:all,
:conditions => [ ‘LOWER(last_name) LIKE ?’,
‘%’ + search.downcase + ‘%’ ],
:order => ‘last_name ASC’,
:limit => 8) unless search.blank?
render :partial => “search”
end
Thanks for any help!
jko170
February 22, 2007, 10:46am
2
I don’t see anything wrong with:
@users = User.find(:all,
:conditions => [ ‘LOWER(last_name) LIKE ? OR LOWER(last_name)
LIKE ?’,
“%{search.downcase}%”, “%{search.downcase}%” ],
:order => ‘last_name ASC’,
:limit => 8)
Not able to test right now, mind you.
jko170
February 22, 2007, 10:46am
3
whoops,
that would be
“%#{search.downcase}%”, “%#{search.downcase}%”
sorry.
jko170
February 22, 2007, 12:49pm
4
I see where I went wrong. Works perfect, thanks!