Faster Auto-Completion with Rails
Auto-Complete is a great tool when it provides possible results BEFORE you finish typing. Unfortunately, using Rails’s included AJAX helpers to query the database as you type often results in a large delay before matches are returned.
In a client project, users can add labels to events on their calendar. To prevent users from creating variations of the same label name (i.e. – “favorite” vs. “favorites”), we needed to provide faster auto-complete functionality than that available through Rails’s provided AJAX helpers.
Take a look at the local_auto_complete_field helper method. TXT (Editor’s note: this is no longer available.)
To call the function from your views:
<br></br> <%= local_auto_complete_field('name',@labels) %><br></br>
#name on each element in the
@labels array. To override this behavior:
<%= local_auto_complete_field('name',@labels, :method => 'description') %>
Here’s to faster auto-completion!