Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Autocomplete throws Uncaught TypeError: Object has no method 'autocomplete'

I'm trying to introduce the jQuery UI autocomplete feature to a widget in a Rails 3.1.3 app. It doesn't do anything and on inspecting the scripts in Chrome developer tools, I see the following:

jQuery(function() {
  return $("#location").autocomplete({
    locations.js:3 Uncaught TypeError: Object #<Object> has no method 'autocomplete'
    source: ["foo", "food", "four"]
  });
});

I've included jQuery UI in application.js:

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require_tree .

My coffeescript has the following:

jQuery ->
  $('#location').autocomplete
    source: ["foo", "food", "four"]

What am I missing!?

like image 589
hgujral Avatar asked Jul 14 '26 10:07

hgujral


1 Answers

It turns out that since I also had active_admin, "//=require_tree ." was adding an older version of jQuery from the active_admin/vendor path which was removing the autocomplete method. Got rid of the "//=require_tree ." for now and explicitly added "//=require locations" and it works just fine.

like image 126
hgujral Avatar answered Jul 17 '26 22:07

hgujral