Ruby on Rails : a dynamic pick list for 1000+ candidates

I am working on a Ruby on Rails project where I need to associated 2 tables. A pick-list “” is good for a short list (less than 20). If I have a very long list, let say picking a stock out of thousand stocks in stock market for an trading order, what should I do?

I saw some dynamic search pick list, I mean the pick list is updated whenever I type one character. DO i have to do it in Javascript ?

Thanks in advance.


​This can be done with jquery. On the change event of the textbox , make an ajax call to a action which takes in the typed text and returns a json array of objects to be populated in the list. In the success handler of the ajax call, remove all existing elements in the list and add the new ones returned by the action.

If you use angular, this can be done more elegantly than in JQuery.​

That way will involve a server request for every character typed, since that could easily be several seconds and maybe a lot more this will introduce intolerable delays for the user.

For acceptable performance send the complete list to the browser and manage the selection in javascript.


​I implemented this with a three character minimum input and the delay was minimum - Barely a fraction of a second. ​ The server based approach works very well with an indexed column on the DB for even 10K records.

Thanks, Ganesh

Was that across the internet? If so you must have a good internet connection and a good server. Try it on a weak mobile connection with a slow server the other side of the world.