2011-05-20 30 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