我有一个控制器指定将值传递给ajax但是在执行时没有打印任何值,这是我的代码:
:用户控制器
def search_name
@nama = params[:name] //Get a value from user input
@user = User.select(:name).where(['name = ?', params[@nama]]).all
respond_to do |format|
format.json {render :json => @user}
format.html { render :json => @user}
end
end
:my.js
$.ajax({
url: '/users/search_name/',
type:'get',
data:{
name:nama
},
dataType:'json',
success:function(puser){
var userName = '';
for(x in puser){
userName += 'Name here"'+ puser[x]['user']['name'] +'";
}
$('.search-result').html(userName);
}
})