In my Rails app, I want to an incremental search (like autoplete) through the Customer
table in the DB, looking for names, and showing the results as you type, Google Instant-style.
My brief research for gems or examples that might help in this scenario didn't provide any useful results.
Is there a Rails way to implement this?
The only issue I can think of is that that having approx. 500k records in the DB (even if the name related columns are indexed) might slow down the responsiveness.
As a solution for that, the ajax request might be triggered only after typing in the first 4-5 characters.
Any other suggestions, leads, issues, ideas, ments?
In my Rails app, I want to an incremental search (like autoplete) through the Customer
table in the DB, looking for names, and showing the results as you type, Google Instant-style.
My brief research for gems or examples that might help in this scenario didn't provide any useful results.
Is there a Rails way to implement this?
The only issue I can think of is that that having approx. 500k records in the DB (even if the name related columns are indexed) might slow down the responsiveness.
As a solution for that, the ajax request might be triggered only after typing in the first 4-5 characters.
Any other suggestions, leads, issues, ideas, ments?
Share Improve this question edited Jun 17, 2011 at 13:55 Marius Butuc asked Jun 17, 2011 at 13:48 Marius ButucMarius Butuc 18.3k23 gold badges80 silver badges111 bronze badges2 Answers
Reset to default 8Use this: Tokeninput
and here is Railscast for it: TokenInput railscast
While I'm not at all familiar with ruby, I use jQuery UI autoplete often. You can trigger it to run only after a certain number of characters are typed (See minLength in 'options').
Also you can pass additional parameters to your server side scripting. I pass one called Limit and set it to a sensible value (10 in most cases), I use this in the SQL query (where rownum <10), that way you don't hammer the database.