Search code examples
ruby-on-rails-4bootstrap-typeahead

typeahead autocomplete doesn't work sometimes


I implemented Typeahead autocomplete with Rails 4 using elasticsearch, searchkick and bootstrap. It works fine when I reload the webpage, but doesn't work when the cached page is loaded. I wonder where should I start to fix the problem.

Here is the snippet of my js code:

$ ->
  $('#profile_search').typeahead
  name: "profile"
  remote: "/profiles/autocomplete?query=%QUERY"

Solution

  • Try something like this. Here is my working variant.

    remote:{
             url: '/profiles/autocomplete?query=%QUERY',
                   filter: function(parsedResponse) {
                   return parsedResponse.data;
                   }
                },
        prefetch: '/profiles/autocomplete?query=%QUERY';