# Text\_field\_with\_auto\_complete (newbie question)

**URL:** <https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849>\
**Category:** Rails\
**Created:** [May 17, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849 "2006-05-17T23:15:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 17, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849/1 "2006-05-17T23:15:28Z")

</div>

I have the text\_field\_with\_auto\_complete woking on my user DB using  
last\_name. so looking for ‘ivanoff’ works great, but I can’t find  
‘john’. Plus I like to have ‘last\_name, first\_name’ show up in the  
dropdown.

what I can’t figure out is how to concat first\_name and last\_name to  
make a name and use that to look it.

working code  
\<%= text\_field\_with\_auto\_complete :user, :last\_name %\>

where do I concatinate first\_name and last\_name to make a name?

thanks  
John

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 18, 2006, 1:47am UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849/2 "2006-05-18T01:47:21Z")

</div>

On Wed, 2006-05-17 at 16:12 -0500, John I. wrote:

> where do I concatinate first\_name and last\_name to make a name?

* * *

check the wiki and api for ‘aggregations’

The topic is covered in Agile Web D. for Rails as well.

Craig

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 18, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849/3 "2006-05-18T17:10:06Z")

</div>

thanks,  
I understand what that does but I couldn’t get it to work.  
it was looking for the ‘name’ column in the database but I followed  
the examples in the book (changing the variable names where needed)  
maybe my mapping isn’t right.

I found something that will work although it’s not what I really want  
to do. [http://demo.script.aculo.us/ajax/autocompleter\_customized](http://demo.script.aculo.us/ajax/autocompleter_customized)

using this I can only look at the last name but at least the fisrt  
name is now displaying. (yes I’m cringing too) I’ll get back to the  
‘aggregations’ because I’d like to be able to look up by first name as  
well as last name.

thanks.

john

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 18, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849/4 "2006-05-18T17:33:09Z")

</div>

On Thu, 2006-05-18 at 10:07 -0500, John I. wrote:

> name is now displaying. (yes I’m cringing too) I’ll get back to the
> 
> > > last\_name. so looking for ‘ivanoff’ works great, but I can’t find
> > 
> > * * *
> > 
> > check the wiki and api for ‘aggregations’
> > 
> > The topic is covered in Agile Web D. for Rails as well.

* * *

perhaps this will help…

controller code

# Provides ajax auto complete list rather than using pop-up list

def auto\_complete\_for\_placement\_clwholename  
auto\_complete\_responder\_for\_clients params[:placement][:clwholename]  
end

private

# Controller code for auto create

def auto\_complete\_responder\_for\_clients(value)  
@clients = Client.find(:all,  
:conditions =\> [“LOWER(first\_name||middle\_initial||last\_name)  
LIKE ?”,  
‘%’ + params[:placement][:clwholename].downcase + ‘%’],  
:order =\> ‘last\_name ASC’,  
:limit =\> 8)  
render :partial =\> ‘auto\_cl’  
end

view code…

Client  
  
\<%= text\_field\_with\_auto\_complete :placement, :clwholename, {} %

> 

and my partial \_auto\_cl.rhtml

\<% for client in @clients do -%\>- 
\<%=h client.clwholename %\>-\<%= client.id % \>
\<% end -%\>

Craig

Craig

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 18, 2006, 8:28pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849/5 "2006-05-18T20:28:57Z")

</div>

Where’s mt staples “that was easy” button?

just one change.  
from  
:conditions =\> [“LOWER(first\_name||middle\_initial||last\_name) LIKE ?”,  
to  
:conditions =\> [“LOWER(Concat(last\_name, ', ', first\_name)) LIKE ?”,

mysql doesn’t like || or + to caoncatenate.

thanks.

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 18, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-newbie-question/60849/6 "2006-05-18T22:46:09Z")

</div>

Glad it worked for you…it took me a while to figure out the || for  
postgres

Craig
