我試着去自動填充文本提起使用jQuery插件自動完成,但即時通訊中的一對夫婦的問題上運行,沒有列表視圖genrated和我firbug得到一個錯誤說:使用jquery和RoR錯誤自動填充?
500 Internal Server Error, <h1>Template is missing</h1>
<p>Missing template messages/query with {:handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en], :formats=>[:json, :js, "*/*"]} in view paths "/Users/aldeirm2/Desktop/CMS2/app/views"</p>.
即時猜測它有我試圖返回json對象的方式?
這裏是JavaScript代碼:
$(function() {
var cache = {},
lastXhr;
$("#username").autocomplete({
minLength: 1,
source: function(request, response) {
var term = request.term;
if (term in cache) {
response(cache[ term ]);
return;
}
lastXhr = $.getJSON("/usernames", request, function(data, status, xhr) {
cache[ term ] = data;
if (xhr === lastXhr) {
response(data);
}
});
}
});
});
HTML代碼:在控制器
<label for="username">To:</label> <input id="username" /><br />
搜索方法(路由到使用的 「/搜索」):
def query
@users = User.auto_fill(params[:term])
logger.debug "This is the USERS" + @users.first.username
return @users.collect{|x| {:label => x.name, :id => x.id}}.to_json
end
auto_fill方法在型號:
def self.auto_fill(search)
query = "%#{search}%"
where("username like ?", query)
end
任何幫助將非常感謝。