我想实现自动完成表单数错误下面这个例子How to set up jquery ui autocomplete in rails的参数-trying实现自动完成与jQueryUI的
当我去http://localhost:3000/initiatives/10.json?term=Ion我得到一个“的参数1错误号0” 。
在我的举措#表明我有以下代码:
if params[:term]
Error points to this line - @people = User.all(:all, :conditions => ['name LIKE ?', "#{params[:term]}%"])
else
@people = User.all
end
respond_to do |format|
format.html
format.json { render :json => @people.to_json }
end
我使用PostgreSQL和我想查询是不是该数据库制作。
这是自动完成的脚本:
<script type="text/javascript">
$(function() {
$('#delegatee').autocomplete({
minLength: 2,
source: '<%= json_path %>',
focus: function(event, ui) {
console.log("xxxxxx");
console.log(ui);
$('#delegatee').val(ui.item.name);
return false;
},
select: function(event, ui) {
$('#delegatee').val(ui.item.name);
$('#delegatee_id').val(ui.item.id);
return false;
}
})
.data("uiAutocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.name + "</a>")
.appendTo(ul);
};
});
</script>
“<%= json_path%>” 导致/initiatives/:id.json这使得数据..正确,我认为。
当我尝试的形式出它给了我在控制台中,我相信这是我上面描述的一个500内部服务器错误,并指出我此行的jQuery脚本:xhr.send((options.hasContent && options.data) || null);
我m使用Rails 4.2.0.beta4和Ruby 2.0.0p195。