【发布时间】:2015-04-10 16:41:26
【问题描述】:
我正在尝试按照此示例 How to set up jquery ui autocomplete in rails 实现自动完成表单
当我转到 http://localhost:3000/initiatives/10.json?term=Ion 时,我得到一个“错误的参数数量 1 对 0”。
在我的倡议#show 中,我有以下代码:
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>
"" 导致 /initiatives/:id.json 呈现数据..我认为正确。
当我尝试表单时,它在控制台中给我一个 500 Internal Server 错误,我相信这是我上面描述的错误,它指向我在 jquery 脚本中的这一行:xhr.send( ( options.hasContent && options.data ) || null );
我正在使用 Rails 4.2.0.beta4 和 Ruby 2.0.0p195。
【问题讨论】: