最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Instant-style search in Rails3 - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 8

Use 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.

发布评论

评论列表(0)

  1. 暂无评论