Typeahead for rails with remote data

65 views Asked by At

currently my typeahead works on my local machine with thise

$(document).ready(function(d){
var companies = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        //url: '/javascripts/company_list.json',
        url: 'http://localhost:3000/?utf8=%E2%9C%93&search=%QUERY'
    }
});

I was wondering if I did the url part correctly? It works with that, but I feel like I hardcoded it and wanted to know the best way to handle that if I were to move it to heroku. Thanks!

1

There are 1 answers

1
Adrian Halaburda On BEST ANSWER
var departaments = new Bloodhound({
    datumTokenizer: function(d) {
        return Bloodhound.tokenizers.whitespace(d.value);
       },queryTokenizer: Bloodhound.tokenizers.whitespace,
    limit: 6,
    remote: '/departaments?value=%QUERY'
});

with this just only works for me, but in your case maybe is

remote: '/?value=%QUERY'