2011-05-20 92 views
1

我在Rails应用程序中使用了jquery ui自动完成功能,并且我的结果没有呈现。在firebug中,我得到了一个304没有修改的错误,即使在响应下我看到了正确的字符串响应作为数组。即使收到响应,jquery ui自动完成结果也不会呈现

这里是我的代码:

自动完成控制器:

class AutocompleteController < ApplicationController 
    respond_to :json 

    # result is array of strings eg: ["foo", "foobar", "foobarbat"] 
    def work_fandom 
    @results = redis_tag_lookup(params[:term]) 
    respond_with(@results) 
    end 
end 

在application.js中:

// Autocomplete 
jQuery(function($){ 
    $('.autocomplete').each(function(){ 
    var self = $(this); 
    self.autocomplete({ 
     source: self.attr('autocomplete_method'), 
     minLength: 3 
    }); 
    }); 
}); 

在视图中加载后:

<input aria-haspopup="true" aria-autocomplete="list" role="textbox" autocomplete="off" 
autocomplete_method="/autocomplete/work_fandom" class="autocomplete ui-autocomplete-input ui-autocomplete-loading" 
id="work_fandom" name="work[fandom_string]" value="" type="text"> 

任何建议开山鼻祖电子!

回答

0

尝试respond_with(@ results.to_json)

+0

它看起来像实际上的问题是,jQuery用户界面自动完成期望的结果是在数组{:标签=>标签,:值=>值}散列! – shalott 2011-05-24 17:51:04