<%= button_to_function "保存", "check_feedback(this)" %> <% end %>
<script type="text/javascript"> function check_feedback(form){ var chkStatus1 = document.getElementsByName("active[stu_reg_inf_ids][]"); for (i = 0; i < chkStatus1.length; i++) { if (chkStatus1[i].checked==true){ document.getElementById('stu_reg_infids').value=document.getElementById('stu_reg_infids').value+","+chkStatus1[i].value } } document.forms[1].submit(); return true; } </script>
CONTROLLER:
def active_search_stu cad_students_search#多条件查询方法,返回查询结果集。 @stu_reg_inf_ids=[] if params[:stu_reg_inf_ids]&¶ms[:stu_reg_inf_ids]!=[]#上次搜索的记录 @students_ids=[] students_ids=params[:stu_reg_inf_ids].split(",") for students_id in students_ids student_id=students_id.to_i if student_id>0 @students_ids<<students_id end end for stu_reg_inf in @stu_reg_infs if @students_ids.include?stu_reg_inf.id.to_s#查询记录已包含本次查询的某一对象 @students_ids.delete stu_reg_inf.id.to_s#删除上次记录保留本次记录 end end @studentsids=[] if params[:active] if params[:active][:stu_reg_inf_ids] for stu_reg_inf_id in @students_ids if params[:active][:stu_reg_inf_ids].include?(stu_reg_inf_id.to_s)#上次查询 对象出现在本次打对勾的集体当中 @studentsids<<stu_reg_inf_id end end @students_ids=@studentsids#新的赋值 end else#此次提交为空 @students_ids=[]#从数组中删除,清空数组 end if @students_ids!=[] for stu_reg_inf_id in @students_ids @stu_reg_inf_ids<<stu_reg_inf_id stu_reg_inf=StuRegInf.find(stu_reg_inf_id) @stu_reg_infs<<stu_reg_inf end end @stu_reg_infs = @stu_reg_infs.paginate( :page => params[:page],:per_page =>100, :order =>'convert(created_at using gbk)desc',:order => 'convert(name using gbk)') end for stu_reg_inf in @stu_reg_infss#本次搜索记录 @stu_reg_inf_ids<<stu_reg_inf.id end @stu_reg_infids="" for stu_reg_inf_id in @stu_reg_inf_ids @stu_reg_infids=@stu_reg_infids+","+stu_reg_inf_id.to_s end render :partial=>"/stu_reg_infs/search" end