Sunday, December 11, 2011

jQuery autocomplete source issues

I was trying to get a jQuery version 1.8 autocomplete call to work in Rails 3.1 without using the fancy helpers.  I had something like:

$(function() {
  $('#project-list-autocomplete').autocomplete({
    source: "/rails_controller/json_action"
  });
where json_action is a method that returns the autocomplete values, but I couldn't figure out the format of the JSON. It's:
[{"id":"1", "label":"autoanswer1"}, 
{"id":"2", "label":"autoanswer2"}]

and so on.

No comments: