我的任务是列出学生的详细信息。我想根据姓名和城市进行搜索。如果cityId==0 and name=''
,那么我想列出我所有的学生详细信息。我怎样才能做到这一点?我以错误的方式做到了这一点。控制器是:
if(Student.where(params[:cityId])==0)
studentcount = Student.count()
@students = Student.limit(params[:jtPageSize]).offset(params[:jtStartIndex]).order(params[:jtSorting])
@jtable = {'Result' => 'OK','Records' => @students.map(&:attributes), :TotalRecordCount => studentcount}
else
studentcount = Student.where("name LIKE ? AND city = ?", "%#{params[:name]}%", params[:cityId]).count()
@students = Student.where("name LIKE ? AND city = ?", "%#{params[:name]}%", params[:cityId]).limit(params[:jtPageSize]).offset(params[:jtStartIndex]).order(params[:jtSorting])
@jtable = {'Result' => 'OK','Records' => @students.map(&:attributes), :TotalRecordCount => studentcount}