Hi,
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 number.name, but I’m not sure how to make it display
number.email as well
search_page.rhtml
<input type="text" id="number_lookup" name="number_lookup" /
<div class="auto_complete" id="number_lookup_auto_complete">
</div>
<%= javascript_tag("new Autocompleter.Local('number_lookup',
'number_lookup_auto_complete',
numbers,
{fullSearch: true,
frequency: 0,
minChars: 2
}
);") %>
controller:
def numbers_for_lookup
@numbers = Number.find(:all, :conditions => [“company =
‘#{session[:user_company]}’”])
@headers[‘content-type’] = ‘text/javascript’
render :layout => false
end
numbers_for_lookup.rhtml:
var numbers = new Array(<%= @numbers.size %>);
<% @numbers.each_with_index do |number, index| %>
numbers[<%= index %>] = “<%= number.name %>”;
<% end %>
Any suggestions to how I can display the email address as well in the
result box?
Regards,
Martin S.