I am developing an autocomplete form using JQuery and Rails. However I don’t know how to pull values from my database to JQuery (I believe this has to be done via Rails).
This is my autocomplete function in jQuery
<script>
$(document).ready(function() {
$( "#BOOKSEARCH" ).autocomplete({
source: programmingLang
});
});
var programmingLang = ["ActionScript","AppleScript","Asp","BASIC","C","C++",
"Clojure","COBOL","ColdFusion","Erlang","Fortran","Groovy","Haskell",
"Java","JavaScript","Lisp","Perl","PHP","Python","Ruby","Scala","Scheme"];
</script>
However at the moment the autocomplete fills from a hard coded array. How can a fill this array with my data values from rails?
Thanks
Try this:
Assuming you have a model Language having name column
Make sure you dont have thousands or records, cause that will slow down or even may throw time out error.In that case you should use ajax. There are couple of answers which explain ajax thing.
or