Customized auto complete with preloaded array


I want to have an autocomplete which displays the name and email
address of the contact.
But, the contact list array should be pre loaded, as described in
Rails Recipes.
Since this recipe doesn´t use any partials, I´m not sure how to
accomplish this.

It displays, but I’m not sure how to make it display as well


<input type="text" id="number_lookup" name="number_lookup" /

<div class="auto_complete" id="number_lookup_auto_complete">
<%= javascript_tag("new Autocompleter.Local('number_lookup',
                               {fullSearch: true,
                                  frequency: 0,
                                  minChars: 2
                                );") %>

def numbers_for_lookup
@numbers = Number.find(:all, :conditions => [“company =
@headers[‘content-type’] = ‘text/javascript’
render :layout => false

var numbers = new Array(<%= @numbers.size %>);

<% @numbers.each_with_index do |number, index| %>
numbers[<%= index %>] = “<%= %>”;
<% end %>

Any suggestions to how I can display the email address as well in the
result box?

Martin S.

Actually, you can use a partial. For an autocomplete list the
partial might be named something like _autocomplete.rhtml and would
contain something like the following:

    <% @numbers.each do | number | %>
  • <%= number.number %> <%= %>
  • <% end %>

I don’t have AWDR2 in front of me, but I believe it’s just a
render :partial => ‘autocomplete’, :layout => false

from inside the controller.