Text_field_with_auto_complete (newbie question)


#1

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


#2

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


#3

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

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


#4

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


#5

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.


#6

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

Craig