Jquery ui 参数数量错误-尝试使用jQueryui实现自动完成
我正试图按照这个例子实现一个自动完成表单 当我转到时,我得到了错误数量的0参数1 在我的倡议中,我有以下代码:Jquery ui 参数数量错误-尝试使用jQueryui实现自动完成,jquery-ui,ruby-on-rails-4,Jquery Ui,Ruby On Rails 4,我正试图按照这个例子实现一个自动完成表单 当我转到时,我得到了错误数量的0参数1 在我的倡议中,我有以下代码: 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.h
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>
导致呈现数据的/initiaties/:id.json。。我想是的
当我尝试使用该表单时,控制台中会出现500个内部服务器错误,我相信这就是我在上面描述的错误,它将我指向jquery脚本中的这一行:xhr.send options.hasContent&&options.data | | null
我使用的是Rails 4.2.0.beta4和Ruby 2.0.0p195 在Rails>4.0中,在传递时不要接受多个参数,因此错误的参数数量为1:0
您尝试设置的查询将是:
@people = User.where('name LIKE ?', "#{params[:term]}%")
希望有帮助