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 “f.select” 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.

David

On Fri, Jun 26, 2015 at 7:52 AM, David Ng [email protected] wrote:

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 ?

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

On 26 June 2015 at 08:43, Ganesh Ranganathan
[email protected] wrote:

call, remove all existing elements in the list and add the new ones returned
by the action.

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.

Colin

On Fri, Jun 26, 2015 at 1:20 PM, Colin L. [email protected] wrote:

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.

​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

On 26 June 2015 at 15:57, Ganesh Ranganathan
[email protected] wrote:

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.

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.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs